Use structs/enums

git-svn-id: svn://svn.cc65.org/cc65/trunk@2709 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-12-03 19:57:27 +00:00
parent 788208d7dc
commit 4fa1f8ba97
5 changed files with 52 additions and 50 deletions

View File

@@ -43,13 +43,13 @@
; loader will place informational data if it was successful. You will have to ; loader will place informational data if it was successful. You will have to
; check the return code of mod_load before accessing any of these additional ; check the return code of mod_load before accessing any of these additional
; struct members. ; struct members.
MODCTRL_READ = 0 .struct MOD_CTRL
MODCTRL_CALLERDATA = 2 READ .addr
MODCTRL_MODULE = 4 ; Pointer to module data CALLERDATA .word
MODCTRL_MODULE_SIZE = 6 ; Total size of loaded module MODULE .addr ; Pointer to module data
MODCTRL_MODULE_ID = 8 MODULE_SIZE .word ; Total size of loaded module
MODCTRL_SIZE = 10 ; Total size of struct MODULE_ID .word
.endstruct
; unsigned char mod_load (struct mod_ctrl* ctrl); ; unsigned char mod_load (struct mod_ctrl* ctrl);
; /* Load a module into memory and relocate it. The function will return an ; /* Load a module into memory and relocate it. The function will return an
@@ -65,15 +65,14 @@ MODCTRL_SIZE = 10 ; Total size of struct
; */ ; */
.global _mod_free .global _mod_free
; Errors ; Errors
MLOAD_OK = 0 ; Module load successful .enum
MLOAD_ERR_READ = 1 ; Read error MLOAD_OK ; Module load successful
MLOAD_ERR_HDR = 2 ; Header error MLOAD_ERR_READ ; Read error
MLOAD_ERR_OS = 3 ; Wrong OS MLOAD_ERR_HDR ; Header error
MLOAD_ERR_FMT = 4 ; Data format error MLOAD_ERR_OS ; Wrong OS
MLOAD_ERR_MEM = 5 ; Not enough memory MLOAD_ERR_FMT ; Data format error
MLOAD_ERR_MEM ; Not enough memory
.endenum

View File

@@ -34,31 +34,34 @@
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Offsets into the driver header ; The driver header
SER_HDR_ID = 0 ; Contains 0x73, 0x65, 0x72 ("ser") .struct SER_HDR
SER_HDR_VERSION = 3 ; Interface version ID .byte 3 ; Contains 0x73, 0x65, 0x72 ("ser")
VERSION .byte 1 ; Interface version
JUMPTAB .struct
INSTALL .word ; INSTALL routine
UNINSTALL .word ; UNINSTALL routine
OPEN .word ; OPEN routine
CLOSE .word ; CLOSE routine
GET .word ; GET routine
PUT .word ; PUT routine
STATUS .word ; STATUS routine
IOCTL .word ; IOCTL routine
.endstruct
.endstruct
SER_HDR_JUMPTAB = 4
SER_HDR_INSTALL = SER_HDR_JUMPTAB+0 ; INSTALL routine
SER_HDR_UNINSTALL = SER_HDR_JUMPTAB+2 ; UNINSTALL routine
SER_HDR_OPEN = SER_HDR_JUMPTAB+4 ; OPEN routine
SER_HDR_CLOSE = SER_HDR_JUMPTAB+6 ; CLOSE routine
SER_HDR_GET = SER_HDR_JUMPTAB+8 ; GET routine
SER_HDR_PUT = SER_HDR_JUMPTAB+10 ; PUT routine
SER_HDR_STATUS = SER_HDR_JUMPTAB+12 ; STATUS routine
SER_HDR_IOCTL = SER_HDR_JUMPTAB+14 ; IOCTL routine
SER_HDR_JUMPCOUNT = 8 ; Number of jump vectors
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Offsets into the struct passed to ser_params ; ser_params
SER_PARAMS_BAUDRATE = 0 ; Baudrate .struct SER_PARAMS
SER_PARAMS_DATABITS = 1 ; Number of data bits BAUDRATE .byte ; Baudrate
SER_PARAMS_STOPBITS = 2 ; Number of stop bits DATABITS .byte ; Number of data bits
SER_PARAMS_PARITY = 3 ; Parity setting STOPBITS .byte ; Number of stop bits
SER_PARAMS_HANDSHAKE = 4 ; Type of handshake to use PARITY .byte ; Parity setting
HANDSHAKE .byte ; Type of handshake to use
.endstruct
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Serial parameters ; Serial parameters

View File

@@ -63,7 +63,7 @@ ACIA_CLOCK = ACIA+7 ; Turbo232 external baud-rate generator
; Global variables ; Global variables
; ;
; We reuse the RS232 zero page variables for the driver, since the ROM ; We reuse the RS232 zero page variables for the driver, since the ROM
; routines cannot be used together with this driver. ; routines cannot be used together with this driver.
RecvHead = $B5 ; Head of receive buffer RecvHead = $B5 ; Head of receive buffer
RecvTail = $BD ; Tail of receive buffer RecvTail = $BD ; Tail of receive buffer
@@ -183,7 +183,7 @@ OPEN:
; Check if the handshake setting is valid ; Check if the handshake setting is valid
ldy #SER_PARAMS_HANDSHAKE ; Handshake ldy #SER_PARAMS::HANDSHAKE ; Handshake
lda (ptr1),y lda (ptr1),y
cmp #SER_HS_HW ; This is all we support cmp #SER_HS_HW ; This is all we support
bne InvParam bne InvParam
@@ -195,21 +195,21 @@ OPEN:
; Set the value for the control register, which contains stop bits, word ; Set the value for the control register, which contains stop bits, word
; length and the baud rate. ; length and the baud rate.
ldy #SER_PARAMS_BAUDRATE ldy #SER_PARAMS::BAUDRATE
lda (ptr1),y ; Baudrate index lda (ptr1),y ; Baudrate index
tay tay
lda BaudTable,y ; Get 6551 value lda BaudTable,y ; Get 6551 value
bmi InvBaud ; Branch if rate not supported bmi InvBaud ; Branch if rate not supported
sta tmp1 sta tmp1
ldy #SER_PARAMS_DATABITS ; Databits ldy #SER_PARAMS::DATABITS ; Databits
lda (ptr1),y lda (ptr1),y
tay tay
lda BitTable,y lda BitTable,y
ora tmp1 ora tmp1
sta tmp1 sta tmp1
ldy #SER_PARAMS_STOPBITS ; Stopbits ldy #SER_PARAMS::STOPBITS ; Stopbits
lda (ptr1),y lda (ptr1),y
tay tay
lda StopTable,y lda StopTable,y
@@ -220,7 +220,7 @@ OPEN:
; Set the value for the command register. We remember the base value in ; Set the value for the command register. We remember the base value in
; RtsOff, since we will have to manipulate ACIA_CMD often. ; RtsOff, since we will have to manipulate ACIA_CMD often.
ldy #SER_PARAMS_PARITY ; Parity ldy #SER_PARAMS::PARITY ; Parity
lda (ptr1),y lda (ptr1),y
tay tay
lda ParityTable,y lda ParityTable,y

View File

@@ -90,7 +90,7 @@ ExpectedHdrSize = * - ExpectedHdr
.code .code
PushCallerData: PushCallerData:
ldy #MODCTRL_CALLERDATA+1 ldy #MOD_CTRL::CALLERDATA+1
lda (Ctrl),y lda (Ctrl),y
tax tax
dey dey
@@ -336,7 +336,7 @@ _mod_load:
; Get the read function pointer from the control structure and place it into ; Get the read function pointer from the control structure and place it into
; our call vector ; our call vector
ldy #MODCTRL_READ ldy #MOD_CTRL::READ
lda (Ctrl),y lda (Ctrl),y
sta Read+1 sta Read+1
iny iny
@@ -397,10 +397,10 @@ Opt: jsr ReadByte ; Read the length byte
bne OSError ; Wrong version bne OSError ; Wrong version
jsr ReadByte ; Get low byte of id jsr ReadByte ; Get low byte of id
ldy #MODCTRL_MODULE_ID ldy #MOD_CTRL::MODULE_ID
sta (Ctrl),y sta (Ctrl),y
jsr ReadByte jsr ReadByte
ldy #MODCTRL_MODULE_ID+1 ldy #MOD_CTRL::MODULE_ID+1
sta (Ctrl),y sta (Ctrl),y
inc TPtr+1 ; Remember that we got the OS inc TPtr+1 ; Remember that we got the OS
@@ -448,7 +448,7 @@ CalcSizes:
lda TPtr lda TPtr
add Header + O65_HDR_BLEN add Header + O65_HDR_BLEN
pha ; Save low byte of total size pha ; Save low byte of total size
ldy #MODCTRL_MODULE_SIZE ldy #MOD_CTRL::MODULE_SIZE
sta (Ctrl),y sta (Ctrl),y
lda TPtr+1 lda TPtr+1
adc Header + O65_HDR_BLEN + 1 adc Header + O65_HDR_BLEN + 1
@@ -465,7 +465,7 @@ CalcSizes:
sta Module sta Module
stx Module+1 stx Module+1
ldy #MODCTRL_MODULE ldy #MOD_CTRL::MODULE
sta (Ctrl),y sta (Ctrl),y
txa txa
iny iny

View File

@@ -59,12 +59,12 @@ _ser_install:
; Copy the jump vectors ; Copy the jump vectors
ldy #SER_HDR_JUMPTAB ldy #SER_HDR::JUMPTAB
ldx #0 ldx #0
@L1: inx ; Skip the JMP opcode @L1: inx ; Skip the JMP opcode
jsr copy ; Copy one byte jsr copy ; Copy one byte
jsr copy ; Copy one byte jsr copy ; Copy one byte
cpx #(SER_HDR_JUMPCOUNT*3) cpx #(SER_HDR::JUMPTAB + .sizeof(SER_HDR::JUMPTAB))
bne @L1 bne @L1
jmp ser_install ; Call driver install routine jmp ser_install ; Call driver install routine