Merge pull request #49 from Russell-S-Harper/development

Adding handling for different section types.
This commit is contained in:
Russell-S-Harper 2019-04-29 21:37:47 -04:00 committed by GitHub
commit 270d613c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 34 deletions

View File

@ -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 xa -C -M page6.asm -l page6.lbl -o page6.obj
globals.h: common.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: clean:
rm -f globals.h page6.asm common.obj page6.obj common.lbl page6.lbl system.obj rm -f globals.h page6.asm common.obj page6.obj common.lbl page6.lbl system.obj

View File

@ -2,7 +2,7 @@
#include "common.h" #include "common.h"
; ROM code header ; ROM code header
.BYTE CODE .BYTE _SM_FXD
.WORD CMN_CD, _END_CMN_CD - CMN_CD .WORD CMN_CD, _END_CMN_CD - CMN_CD
; beginning of ROM code ; beginning of ROM code
@ -1054,7 +1054,7 @@ _3 ORA _F
_END_CMN_CD _END_CMN_CD
; ROM data header ; ROM data header
.BYTE DATA .BYTE _SM_FXD
.WORD CMN_DT, _END_CMN_DT - CMN_DT .WORD CMN_DT, _END_CMN_DT - CMN_DT
; beginning of ROM data ; beginning of ROM data
@ -1072,7 +1072,7 @@ MNS_1 .BYTE $00, $fc, $ff, $ff
_END_CMN_DT _END_CMN_DT
; 6502 addresses ; 6502 addresses
.BYTE DATA .BYTE _SM_FXD
.WORD ADDR, 6 .WORD ADDR, 6
; 6502 NMI, Reset and IRQ ; 6502 NMI, Reset and IRQ

View File

@ -156,8 +156,14 @@ _MSK_R = %00111100 ; mask for registers
_MSK_T = (_F_Z + _F_P + _F_N) ^ $ff ; mask for TST _MSK_T = (_F_Z + _F_P + _F_N) ^ $ff ; mask for TST
_MSK_C = (_F_E + _F_G + _F_L) ^ $ff ; mask for CMP _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 ; section identifiers
CODE = %10101010 ; to indicate CODE section _RLC_CD = _SM_RLC + _SM_CD ; relocatable code
DATA = %01010101 ; to indicate DATA section _RLC_DT = _SM_RLC + _SM_DT ; relocatable data
#endif /* __COMMON_H */ #endif /* __COMMON_H */

View File

@ -77,9 +77,23 @@
#define MOD(r, p, q) .BYTE _MOD_C + (r), _MRG_M(p, q) #define MOD(r, p, q) .BYTE _MOD_C + (r), _MRG_M(p, q)
#define EXT(f) .BYTE _EXT_C + (f) #define EXT(f) .BYTE _EXT_C + (f)
; header, begin and end of blocks ; header for fixed code or data
#define HDR(t, a) .BYTE t:.WORD a, _END_##a - a:* = * - 5:a .( #define HARD(l) .BYTE _SM_FXD:.WORD l, _END_##l - l:* = * - 5:l .(
#define BGN(a) a .(
#define END(a) .):_END_##a ; 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 */ #endif /* __MACROS_H */

View File

@ -2,17 +2,18 @@
#include "macros.h" #include "macros.h"
#include "globals.h" #include "globals.h"
* = $600 * = 0
HDR(CODE, DEMO) CODE(DEMO, DEMO)
CMN CMN
SET(R0, 9.4662) SET(R0, 9.4662)
SET(R1, 0) SET(R1, 0)
LDI(R7, R1)
SVI(R1, R0) SVI(R1, R0)
PSH(R0) PSH(R0)
BRS(FACTORIAL) BRS(FACTORIAL)
POP(R4) POP(R4)
SET(R5, 0) SET(R5, 1)
LDI(R6, R5) LDI(R6, R5)
ESC ESC
BRK BRK
@ -33,9 +34,7 @@ END(FACTORIAL)
END(DEMO) END(DEMO)
HDR(DATA, WORKING) DATA(WORKING, EXTRA)
+PI INIT(3.1415926535)
ONE .BYTE 0, 0, 0, 0 +EXTRA ZERO(2)
TWO .BYTE 0, 0, 0, 0
END(WORKING) END(WORKING)

View File

@ -25,8 +25,15 @@
#define _CR _CRL /* code memory address */ #define _CR _CRL /* code memory address */
#define _AR _ARL /* allocated memory address */ #define _AR _ARL /* allocated memory address */
#define CODE 0xaa /* to indicate CODE section */ /* section modifiers */
#define DATA 0x55 /* to indicate DATA section */ #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]; uint8_t memory[65536];
@ -61,27 +68,46 @@ void hook() {
int main() { int main() {
uint8_t header[5]; uint8_t header[5];
/* where to start relocatables */
uint16_t index = 0x0600;
while (fread(header, sizeof(header), 1, stdin)) while (fread(header, sizeof(header), 1, stdin))
{ {
uint8_t type = header[0]; 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); 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 _SM_FXD: /* fixed code or data */
switch (type) { /* entity is the address, length is the length of the code or data */
case CODE: fread(memory + entity, length, 1, stdin);
memory[_CRL] = header[1]; break;
memory[_CRH] = header[2];
break; case _RLC_CD: /* relocatable code */
case DATA: /* entity is the starting offset, length is the length of code */
memory[_ARL] = header[1]; if (fread(memory + index, length, 1, stdin)) {
memory[_ARH] = header[2]; /* offset the starting address */
break; 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;
} }
} }