Skip to content

Commit ad71946

Browse files
committed
Decoding rework WIP
1 parent ca8a987 commit ad71946

59 files changed

Lines changed: 3511 additions & 1019 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
cmake_minimum_required (VERSION 3.30)
1+
cmake_minimum_required(VERSION 4.3.0)
22

33
project(etripator
4-
VERSION 0.9.0
5-
LANGUAGES C)
4+
VERSION 1.0.0
5+
LANGUAGES C
6+
)
7+
8+
if(NOT CMAKE_BUILD_TYPE)
9+
message(STATUS, "No build type specified. Force build type to Debug.")
10+
set(CMAKE_BUILD_TYPE "Debug")
11+
endif()
12+
13+
set(CMAKE_C_STANDARDS 11)
14+
add_compile_options(-Wall -Wextra -Wshadow)
615

716
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
817
add_compile_definitions(_DARWIN_C_SOURCE=__DARWIN_C_FULL)
@@ -15,67 +24,15 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1524
enable_testing()
1625

1726
include(CheckSymbolExists)
18-
1927
check_symbol_exists(strdup "string.h" HAVE_STRDUP)
2028

21-
if(NOT CMAKE_BUILD_TYPE)
22-
message(STATUS, "No build type specified. Force build type to Debug.")
23-
set(CMAKE_BUILD_TYPE "Debug")
24-
endif()
25-
26-
find_package(Doxygen)
2729
find_package(Jansson)
2830

29-
set(CMAKE_C_STANDARDS 11)
30-
3131
add_subdirectory(externals EXCLUDE_FROM_ALL)
3232

33-
set(etripator_SRC
34-
message.c
35-
message/file.c
36-
message/console.c
37-
jsonhelpers.c
38-
decode.c
39-
section.c
40-
section/load.c
41-
section/save.c
42-
opcodes.c
43-
comment.c
44-
comment/load.c
45-
comment/save.c
46-
label.c
47-
label/load.c
48-
label/save.c
49-
irq.c
50-
memory.c
51-
memory_map.c
52-
rom.c
53-
cd.c
54-
ipl.c
55-
output.c
56-
# wla_dx.c
57-
)
33+
add_subdirectory(src)
5834

59-
set(etripator_HDR
60-
config.h
61-
message.h
62-
message/file.h
63-
message/console.h
64-
jsonhelpers.h
65-
decode.h
66-
section.h
67-
opcodes.h
68-
comment.h
69-
label.h
70-
irq.h
71-
memory.h
72-
memory_map.h
73-
rom.h
74-
cd.h
75-
ipl.h
76-
output.h
77-
# wla_dx.h
78-
)
35+
#[[
7936
8037
add_library(etripator STATIC ${etripator_SRC} ${etripator_HDR})
8138
set_target_properties(etripator PROPERTIES C_STANDARD 11)
@@ -93,6 +50,12 @@ target_include_directories(etripator_cli PRIVATE ${CMAKE_SOURCE_DIR})
9350
target_include_directories(etripator_cli PUBLIC externals)
9451
target_link_libraries(etripator_cli etripator cargs)
9552
53+
#]]
54+
55+
add_subdirectory(test)
56+
57+
find_package(Doxygen)
58+
9659
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxyfile.in)
9760
set(DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/doxyfile)
9861

@@ -106,6 +69,3 @@ add_custom_target(doc
10669
VERBATIM
10770
)
10871

109-
add_subdirectory(test)
110-
111-
install(TARGETS etripator_cli DESTINATION bin)

externals/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ add_subdirectory(cwalk)
44
add_library(munit STATIC ${CMAKE_CURRENT_LIST_DIR}/munit/munit.c)
55
target_include_directories(munit PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/munit>)
66
set_property(TARGET munit PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/munit>)
7+
target_compile_definitions(munit PRIVATE MUNIT_NO_FORK)
78

89
add_subdirectory(fff)

cd.h renamed to include/etripator/cd.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,33 @@
3737
#define ETRIPATOR_CD_H
3838

3939
#include "config.h"
40+
#include "data.h"
4041
#include "memory_map.h"
4142

42-
#define PCE_CD_RAM_BANK_COUNT 8U
43-
#define PCE_SYSCARD_RAM_BANK_COUNT 24U
43+
#define PCE_CD_RAM_BANK_COUNT (8U)
44+
#define PCE_SYSCARD_RAM_BANK_COUNT (24U)
4445

45-
#define PCE_CD_RAM_FIRST_PAGE 0x80U
46-
#define PCE_SYSCARD_RAM_FIRST_PAGE 0x68U
46+
#define PCE_CD_RAM_FIRST_PAGE (0x80U)
47+
#define PCE_SYSCARD_RAM_FIRST_PAGE (0x68U)
4748

4849
/// Adds CD RAM to memory map.
4950
/// \param map Memory map.
5051
/// \return true if the CD RAM and SYSCARD RAM memory areas were successfully created.
5152
/// \return false if an error occured.
5253
bool cd_memory_map(MemoryMap *map);
5354

55+
// [todo] arcade card
56+
5457
/// Load CDROM data from file.
55-
/// \param [in] filename CDROM data filename.
58+
/// \param [out] map Memory map.
59+
/// \param [in] input Input data.
5660
/// \param [in] start CDROM data offset.
5761
/// \param [in] len CDROM data length (in bytes).
5862
/// \param [in] sector_size CD sector size.
5963
/// \param [in] page Memory page.
6064
/// \param [in] offset Memory page offset.
61-
/// \param [out] map Memory map.
6265
/// \return true
6366
/// \return false
64-
bool cd_load(const char* filename, size_t start, size_t len, size_t sector_size, uint8_t page, size_t offset, MemoryMap* map);
67+
bool cd_load(MemoryMap* map, Data* input, size_t start, size_t len, size_t sector_size, uint8_t page, size_t offset);
6568

6669
#endif // ETRIPATOR_CD_H

comment.h renamed to include/etripator/comment.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@
3737
#define ETRIPATOR_COMMENT_H
3838

3939
#include "config.h"
40+
#include "string.h"
41+
42+
/// @defgroup Comments Comments management
43+
/// @{
4044

4145
/// Comment.
4246
typedef struct {
43-
uint16_t logical; //< Logical address.
44-
uint8_t page; //< Memory page.
45-
char* text; //< Comment text.
47+
uint16_t logical; //< Logical address.
48+
uint8_t page; //< Memory page.
49+
String text; //< Comment text.
4650
} Comment;
4751

4852
/// Comment repository.
@@ -69,7 +73,7 @@ void comment_repository_destroy(CommentRepository* repository);
6973
/// \param [in] text Comment text.
7074
/// \return true if the comment was successfully added to the repository.
7175
/// \return false if an error occured.
72-
bool comment_repository_add(CommentRepository* repository, uint16_t logical, uint8_t page, const char *text);
76+
bool comment_repository_add(CommentRepository* repository, uint16_t logical, uint8_t page, String *text);
7377

7478
/// Find a comment by its address.
7579
/// \param [in] repository Comment repository.
@@ -114,4 +118,6 @@ bool comment_repository_load(CommentRepository* repository, const char* filename
114118
/// \return false if an error occured.
115119
bool comment_repository_save(CommentRepository* repository, const char* filename);
116120

121+
/// @}
122+
117123
#endif // ETRIPATOR_COMMENT_H

config.h renamed to include/etripator/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#ifndef ETRIPATOR_CONFIG_H
3737
#define ETRIPATOR_CONFIG_H
3838

39+
#include <stddef.h>
3940
#include <stdlib.h>
4041
#include <stdio.h>
4142
#include <stdarg.h>

opcodes.h renamed to include/etripator/data.h

Lines changed: 37 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,91 +33,48 @@
3333
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
3434
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
3535
*/
36-
#ifndef ETRIPATOR_OPCODES_H
37-
#define ETRIPATOR_OPCODES_H
36+
#ifndef ETRIPATOR_DATA_H
37+
#define ETRIPATOR_DATA_H
3838

3939
#include "config.h"
4040

41-
/// @defgroup Opcode Opcode
42-
///@{
41+
/// @defgroup DataGroup Data access
42+
/// @{
4343

44-
/// Opcode types:
45-
/// -# `OPC`
46-
/// -# `OPC A`
47-
/// -# `OPC #nn`
48-
/// -# `OPC #nn, ZZ`
49-
/// -# `OPC #nn, ZZ, X`
50-
/// -# `OPC #nn, hhll`
51-
/// -# `OPC #nn, hhll, X`
52-
/// -# `OPC ZZ`
53-
/// -# `OPC ZZ, X`
54-
/// -# `OPC ZZ, Y`
55-
/// -# `OPC (ZZ)`
56-
/// -# `OPC (ZZ, X)`
57-
/// -# `OPC (ZZ), Y`
58-
/// -# `OPC ZZ, hhll`
59-
/// -# `OPC hhll`
60-
/// -# `OPC (hhll)`
61-
/// -# `OPC hhll, X`
62-
/// -# `OPC hhll, Y`
63-
/// -# `OPC shsl,dhdl,hhll`
64-
/// -# `OPC l_hhll` (label)
65-
/// -# `OPC ZZ, l_hhll` (label)
66-
/// -# `OPC [hhll, X]`
67-
/// -# `.db OPC` (unsupported opcode output as raw binary data)
68-
enum PCE_ADDRESSING_MODE {
69-
PCE_OP = 0,
70-
PCE_OP_A,
71-
PCE_OP_nn,
72-
PCE_OP_nn_ZZ,
73-
PCE_OP_nn_ZZ_X,
74-
PCE_OP_nn_hhll,
75-
PCE_OP_nn_hhll_X,
76-
PCE_OP_ZZ,
77-
PCE_OP_ZZ_X,
78-
PCE_OP_ZZ_Y,
79-
PCE_OP__ZZ__,
80-
PCE_OP__ZZ_X__,
81-
PCE_OP__ZZ__Y_,
82-
PCE_OP_ZZ_hhll,
83-
PCE_OP_hhll,
84-
PCE_OP__hhll__,
85-
PCE_OP_hhll_X,
86-
PCE_OP_hhll_Y,
87-
PCE_OP_shsl_dhdl_hhll,
88-
PCE_OP__lbl__,
89-
PCE_OP_ZZ_lbl,
90-
PCE_OP__hhll_X__,
91-
PCE_unknown
92-
};
44+
struct Data;
45+
typedef struct Data Data;
9346

94-
#define OPCODE_NAME_MAX_LEN 5U
95-
96-
/// Opcode
97-
typedef struct {
98-
char name[OPCODE_NAME_MAX_LEN]; //< name
99-
uint8_t size; //< size in bytes
100-
uint8_t type; //< addressing type
101-
} Opcode;
102-
103-
/// Get opcode description
104-
/// \param [in] op Opcode id
105-
/// \return Pointer to opcode description
106-
const Opcode* opcode_get(uint8_t op);
107-
108-
/// Get opcode format string
109-
/// \param [in] op Pointer to opcode description
110-
/// \param [in] i Opcode argument id
111-
/// \return Argument format string
112-
/// \return NULL if the argument id is out of opcode argument count
113-
const char* opcode_format(const Opcode *op, int i);
114-
115-
/// Is the instruction a local jump ?
116-
bool opcode_is_local_jump(uint8_t op);
117-
118-
/// Is the instruction a "far" jump ?
119-
bool opcode_is_far_jump(uint8_t op);
47+
/// Create in memory buffer data.
48+
/// @param [in] buffer Pointer to memory buffer.
49+
/// @param [in] size Memory buffer size.
50+
/// @return Pointer to memory buffer data.
51+
/// @return NULL if buffer is NULL or size is zero.
52+
Data* data_buffer_create(uint8_t *buffer, size_t size);
53+
/// Create file data.
54+
/// @param [in] filename File name.
55+
/// @param [in] mode [TODO]
56+
/// @return Pointer to file data.
57+
/// @return NULL [TODO]
58+
Data* data_file_create(const char *filename, const char* mode);
59+
///
60+
void data_release(Data *data);
61+
///
62+
bool data_open(Data *data);
63+
///
64+
void data_close(Data *data);
65+
///
66+
size_t data_tell(Data *data);
67+
///
68+
size_t data_size(Data *data);
69+
///
70+
bool data_seek(Data *data, ssize_t delta);
71+
///
72+
bool data_jump(Data *data, ssize_t offset);
73+
///
74+
bool data_read(Data *data, uint8_t *buffer, size_t size, size_t *nread);
75+
///
76+
bool data_write(Data *data, const uint8_t *buffer, size_t size, size_t *nwritten);
12077

12178
/// @}
12279

123-
#endif // ETRIPATOR_OPCODES_H
80+
#endif // ETRIPATOR_DATA_H

include/etripator/disasm.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
3+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
4+
5+
__/¯\____ ___/\__ _/\__ _/\_ _/\__ _/\___ ___/\__ __/\_ _/\__
6+
\_ ____/_> ____ \_/ _ \_ \ < /_ \_/ _>> ____ \_ > \_/ _ \_
7+
_> ___/ ¯>__> <<__// __ _/ |> ></ _/> </ ¯ \\__> <<__// /\ // __ _/
8+
_> \7 <__/:. \__/:. \> \_/ L/ _____/. 7> .\_/:. \__/ <_/ </:. \> \_
9+
|:::::::::::::::::::::::/:::::::::::::>::::::::/::::::::::::::::::::::::/:::::|
10+
|¯¯\::::/\:/¯\::::/¯¯¯¯<::::/\::/¯¯\:/¯¯¯¯¯¯\::\::/¯¯\::::/¯¯\::::/¯¯¯¯<::::/¯|
11+
|__ |¯¯| T _ |¯¯¯| ___ |¯¯| |¯| _ T ______ |¯¯¯¯| _ |¯¯¯| _ |¯¯¯| ___ |¯¯| _|
12+
\|__|/\|/ \|___|/ \|__|/\|_|/ \|/ \| |/ \|___|/ \|___|/dNo\|__|/
13+
14+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
15+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
16+
17+
This file is part of Etripator,
18+
copyright (c) 2009--2026 Vincent Cruz.
19+
20+
Etripator is free software: you can redistribute it and/or modify
21+
it under the terms of the GNU General Public License as published by
22+
the Free Software Foundation, either version 3 of the License, or
23+
(at your option) any later version.
24+
25+
Etripator is distributed in the hope that it will be useful,
26+
but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
GNU General Public License for more details.
29+
30+
You should have received a copy of the GNU General Public License
31+
along with Etripator. If not, see <http://www.gnu.org/licenses/>.
32+
33+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
34+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
35+
*/
36+
#ifndef ETRIPATOR_DISASM_H
37+
#define ETRIPATOR_DISASM_H
38+
39+
#include "config.h"
40+
41+
// [todo] nothing atm
42+
43+
#endif // ETRIPATOR_DISASM_H
File renamed without changes.
File renamed without changes.

label.h renamed to include/etripator/label.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#ifndef ETRIPATOR_LABEL_H
3737
#define ETRIPATOR_LABEL_H
3838

39-
#include "config.h"
39+
#include <etripator/config.h>
4040

4141
/// Label.
4242
typedef struct {

0 commit comments

Comments
 (0)