diff --git a/common/Makefile b/common/Makefile index ce92777..81509d7 100644 --- a/common/Makefile +++ b/common/Makefile @@ -11,7 +11,7 @@ page6.obj: rom.h macros.h globals.h page6.src xa -C -M page6.asm -l page6.lbl -o page6.obj globals.h: common.obj - grep -E -v '^(_|CMN_CD|CMN_DT|FN_FX|CODE|DATA)' common.lbl | sed -e 's/, 0, 0x0000//' -e 's/, / = /' -e 's/ 0x/ \x24/' > globals.h + grep -E '^(FN_XR|FN_0X|PLS_1|MNS_1|ADDR)' common.lbl | sed -e 's/, 0, 0x0000//' -e 's/, / = /' -e 's/ 0x/ \x24/' > globals.h clean: rm -f globals.h page6.asm common.obj page6.obj common.lbl page6.lbl system.obj diff --git a/common/common.asm b/common/common.asm index 4c1de7f..285c511 100644 --- a/common/common.asm +++ b/common/common.asm @@ -2,7 +2,7 @@ #include "common.h" ; ROM code header - .BYTE CODE + .BYTE _SM_FXD .WORD CMN_CD, _END_CMN_CD - CMN_CD ; beginning of ROM code @@ -1054,7 +1054,7 @@ _3 ORA _F _END_CMN_CD ; ROM data header - .BYTE DATA + .BYTE _SM_FXD .WORD CMN_DT, _END_CMN_DT - CMN_DT ; beginning of ROM data @@ -1072,7 +1072,7 @@ MNS_1 .BYTE $00, $fc, $ff, $ff _END_CMN_DT ; 6502 addresses - .BYTE DATA + .BYTE _SM_FXD .WORD ADDR, 6 ; 6502 NMI, Reset and IRQ diff --git a/common/common.h b/common/common.h index 8230fbb..f08db35 100644 --- a/common/common.h +++ b/common/common.h @@ -156,8 +156,14 @@ _MSK_R = %00111100 ; mask for registers _MSK_T = (_F_Z + _F_P + _F_N) ^ $ff ; mask for TST _MSK_C = (_F_E + _F_G + _F_L) ^ $ff ; mask for CMP +; section modifiers +_SM_FXD = %00000001 +_SM_RLC = %00000010 +_SM_CD = %00000100 +_SM_DT = %00001000 + ; section identifiers -CODE = %10101010 ; to indicate CODE section -DATA = %01010101 ; to indicate DATA section +_RLC_CD = _SM_RLC + _SM_CD ; relocatable code +_RLC_DT = _SM_RLC + _SM_DT ; relocatable data #endif /* __COMMON_H */ diff --git a/common/macros.h b/common/macros.h index a614151..35d6bf2 100644 --- a/common/macros.h +++ b/common/macros.h @@ -77,9 +77,23 @@ #define MOD(r, p, q) .BYTE _MOD_C + (r), _MRG_M(p, q) #define EXT(f) .BYTE _EXT_C + (f) -; header, begin and end of blocks -#define HDR(t, a) .BYTE t:.WORD a, _END_##a - a:* = * - 5:a .( -#define BGN(a) a .( -#define END(a) .):_END_##a +; header for fixed code or data +#define HARD(l) .BYTE _SM_FXD:.WORD l, _END_##l - l:* = * - 5:l .( + +; header for relocatable code: l(abel), s(tart) => starting offset, length of code +#define CODE(l, s) .BYTE _RLC_CD:.WORD s - l, _END_##l - l: * = * -5:l .( + +; header for relocatable data: l(abel), s(tart) of zeroed data, => length of zeroed data, length of preset data +#define DATA(l, s) .BYTE _RLC_DT:.WORD _END_##l - s, s - l: * = * - 5:l .( + +; initialize memory +#define INIT(v) .BYTE _SET_V(#v) + +; reserve c(ount) +#define ZERO(c) .DSB c * 4, 0 + +; common begin and end +#define BGN(l) l .( +#define END(l) .):_END_##l #endif /* __MACROS_H */ diff --git a/common/page6.src b/common/page6.src index 2b404fc..b9aa874 100644 --- a/common/page6.src +++ b/common/page6.src @@ -2,17 +2,18 @@ #include "macros.h" #include "globals.h" - * = $600 + * = 0 -HDR(CODE, DEMO) +CODE(DEMO, DEMO) CMN SET(R0, 9.4662) SET(R1, 0) + LDI(R7, R1) SVI(R1, R0) PSH(R0) BRS(FACTORIAL) POP(R4) - SET(R5, 0) + SET(R5, 1) LDI(R6, R5) ESC BRK @@ -33,9 +34,7 @@ END(FACTORIAL) END(DEMO) -HDR(DATA, WORKING) - -ONE .BYTE 0, 0, 0, 0 -TWO .BYTE 0, 0, 0, 0 - +DATA(WORKING, EXTRA) ++PI INIT(3.1415926535) ++EXTRA ZERO(2) END(WORKING) diff --git a/emulator/main.c b/emulator/main.c index 564935a..d4ddc67 100644 --- a/emulator/main.c +++ b/emulator/main.c @@ -25,8 +25,15 @@ #define _CR _CRL /* code memory address */ #define _AR _ARL /* allocated memory address */ -#define CODE 0xaa /* to indicate CODE section */ -#define DATA 0x55 /* to indicate DATA section */ +/* section modifiers */ +#define _SM_FXD 0x01 +#define _SM_RLC 0x02 +#define _SM_CD 0x04 +#define _SM_DT 0x08 + +/* section identifiers */ +#define _RLC_CD _SM_RLC + _SM_CD /* relocatable code */ +#define _RLC_DT _SM_RLC + _SM_DT /* relocatable data */ uint8_t memory[65536]; @@ -61,27 +68,46 @@ void hook() { int main() { uint8_t header[5]; + /* where to start relocatables */ + uint16_t index = 0x0600; while (fread(header, sizeof(header), 1, stdin)) { uint8_t type = header[0]; - uint16_t index = header[1] + (header[2] << 8); + uint16_t entity = header[1] + (header[2] << 8); uint16_t length = header[3] + (header[4] << 8); - printf("\n%x %04x %u\n", type, index, length); + printf("\n%x %04x %u\n", type, entity, length); - if (fread(memory + index, length, 1, stdin)) - { - switch (type) { - case CODE: - memory[_CRL] = header[1]; - memory[_CRH] = header[2]; - break; - case DATA: - memory[_ARL] = header[1]; - memory[_ARH] = header[2]; - break; - } + switch (type) { + case _SM_FXD: /* fixed code or data */ + /* entity is the address, length is the length of the code or data */ + fread(memory + entity, length, 1, stdin); + break; + + case _RLC_CD: /* relocatable code */ + /* entity is the starting offset, length is the length of code */ + if (fread(memory + index, length, 1, stdin)) { + /* offset the starting address */ + entity += index; + /* save the starting address */ + memory[_CRL] = entity & 0xff; + memory[_CRH] = entity >> 8; + /* advance to the end of the section */ + index += length; + } + break; + + case _RLC_DT: /* relocatable data */ + /* entity is the length of zeroed data, length is the length of preset data */ + if (fread(memory + index, length, 1, stdin)) { + /* save the start of the data */ + memory[_ARL] = index & 0xff; + memory[_ARH] = index >> 8; + /* advance to the end of the section */ + index += entity + length; + } + break; } }