mirror of
https://github.com/cc65/cc65.git
synced 2025-01-18 11:29:45 +00:00
New calling conventions for read
git-svn-id: svn://svn.cc65.org/cc65/trunk@1548 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
e688abde1f
commit
9c7d2191aa
@ -50,20 +50,24 @@
|
|||||||
* code of mod_load before accessing any of these additional struct members.
|
* code of mod_load before accessing any of these additional struct members.
|
||||||
*/
|
*/
|
||||||
struct mod_ctrl {
|
struct mod_ctrl {
|
||||||
/* Parameters passed into the loader routine. The second pointer
|
/* Parameters passed into the loader routine. The member callerdata
|
||||||
* (callerdata) is an opaque pointer that may be used by the caller to
|
* is an opaque 16 bit datatype that may be used by the caller to
|
||||||
* pass data through to the read routine. The read routine is used by the
|
* pass data through to the read routine. The read routine is used by the
|
||||||
* loader to load any required data. There are several calls where the
|
* loader to load any required data. There are several calls where the
|
||||||
* read routine is called with a size of 1, so you may choose to make this
|
* read routine is passed a count of 1, so you may choose to make this
|
||||||
* a special case when implementing read().
|
* a special case when implementing read(). The read() should return the
|
||||||
|
* number of bytes actually read. If the return value differs from the
|
||||||
|
* passed count, this is considered an error.
|
||||||
|
* NOTE: read() is designed so that the POSIX read() routine can be used
|
||||||
|
* for this vector, if you're loading from disk.
|
||||||
*/
|
*/
|
||||||
unsigned char (*read) (struct mod_ctrl*, void* buffer, unsigned size);
|
int (*read) (int callerdata, void* buffer, unsigned count);
|
||||||
void* callerdata;
|
int callerdata;
|
||||||
|
|
||||||
/* Parameters set by the loader routine */
|
/* Parameters set by the loader routine */
|
||||||
void* module; /* Pointer to module data */
|
void* module; /* Pointer to module data */
|
||||||
unsigned module_size; /* Total size of loaded module */
|
unsigned module_size; /* Total size of loaded module */
|
||||||
unsigned module_id; /* Module id */
|
unsigned module_id; /* Module id */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +81,7 @@ unsigned char mod_load (struct mod_ctrl* ctrl);
|
|||||||
|
|
||||||
void mod_free (void* module);
|
void mod_free (void* module);
|
||||||
/* Free a loaded module. Note: The given pointer is the pointer to the
|
/* Free a loaded module. Note: The given pointer is the pointer to the
|
||||||
* module memory, not a pointer to a control structure.
|
* module memory, not a pointer to a control structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,12 +85,16 @@ ExpectedHdrSize = * - ExpectedHdr
|
|||||||
|
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; PushCtrl: Push the address of the control structure onto the C stack.
|
; PushCallerData: Push the callerdata member from control structure onto the
|
||||||
|
; C stack.
|
||||||
|
|
||||||
.code
|
.code
|
||||||
PushCtrl:
|
PushCallerData:
|
||||||
lda Ctrl
|
ldy #MODCTRL_CALLERDATA+1
|
||||||
ldx Ctrl+1
|
lda (Ctrl),y
|
||||||
|
tax
|
||||||
|
dey
|
||||||
|
lda (Ctrl),y
|
||||||
jmp pushax
|
jmp pushax
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
@ -130,6 +134,47 @@ GetReloc:
|
|||||||
ldx #>__ZP_START__
|
ldx #>__ZP_START__
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
;------------------------------------------------------------------------------
|
||||||
|
; ReadByte: Read one byte with error checking into InputByte and A.
|
||||||
|
; ReadAndCheckError: Call read with the current C stack and check for errors.
|
||||||
|
|
||||||
|
.bss
|
||||||
|
ReadSize: .res 2
|
||||||
|
|
||||||
|
.code
|
||||||
|
ReadByte:
|
||||||
|
|
||||||
|
; C->read (C->callerdata, &B, 1)
|
||||||
|
|
||||||
|
jsr PushCallerData
|
||||||
|
lda #<InputByte
|
||||||
|
ldx #>InputByte
|
||||||
|
jsr pushax
|
||||||
|
ldx #0
|
||||||
|
lda #1
|
||||||
|
|
||||||
|
; This is a second entry point used by the other calls to Read
|
||||||
|
|
||||||
|
ReadAndCheckError:
|
||||||
|
sta ReadSize
|
||||||
|
stx ReadSize+1
|
||||||
|
jsr pushax
|
||||||
|
jsr Read
|
||||||
|
|
||||||
|
; Check the return code and bail out in case of problems
|
||||||
|
|
||||||
|
cmp ReadSize
|
||||||
|
bne @L1
|
||||||
|
cpx ReadSize+1
|
||||||
|
beq @L2 ; Jump if ok
|
||||||
|
@L1: lda #MLOAD_ERR_READ
|
||||||
|
bne CleanupAndExit
|
||||||
|
|
||||||
|
; Done
|
||||||
|
|
||||||
|
@L2: lda InputByte ; If called ReadByte, load the byte read
|
||||||
|
Done: rts
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; FormatError: Bail out with an o65 format error
|
; FormatError: Bail out with an o65 format error
|
||||||
|
|
||||||
@ -174,38 +219,6 @@ CleanupAndExit:
|
|||||||
pla
|
pla
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
|
||||||
; ReadByte: Read one byte with error checking into InputByte and A.
|
|
||||||
; ReadAndCheckError: Call read with the current C stack and check for errors.
|
|
||||||
|
|
||||||
.code
|
|
||||||
ReadByte:
|
|
||||||
|
|
||||||
; C->read (C, &B, 1)
|
|
||||||
|
|
||||||
jsr PushCtrl
|
|
||||||
lda #<InputByte
|
|
||||||
ldx #>InputByte
|
|
||||||
jsr pushax
|
|
||||||
jsr push1
|
|
||||||
|
|
||||||
; This is a second entry point used by the other calls to Read
|
|
||||||
|
|
||||||
ReadAndCheckError:
|
|
||||||
jsr Read
|
|
||||||
|
|
||||||
; Check the return code and bail out in case of problems
|
|
||||||
|
|
||||||
tax
|
|
||||||
beq @L1 ; Jump if ok
|
|
||||||
lda #MLOAD_ERR_READ
|
|
||||||
bne CleanupAndExit
|
|
||||||
|
|
||||||
; Done
|
|
||||||
|
|
||||||
@L1: lda InputByte ; If called ReadByte, load the byte read
|
|
||||||
Done: rts
|
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; RelocSeg: Relocate the segment pointed to by a/x
|
; RelocSeg: Relocate the segment pointed to by a/x
|
||||||
|
|
||||||
@ -331,14 +344,14 @@ _mod_load:
|
|||||||
lda (Ctrl),y
|
lda (Ctrl),y
|
||||||
sta Read+2
|
sta Read+2
|
||||||
|
|
||||||
; Read the o65 header: C->read (C, &H, sizeof (H))
|
; Read the o65 header: C->read (C->callerdata, &H, sizeof (H))
|
||||||
|
|
||||||
jsr PushCtrl
|
jsr PushCallerData
|
||||||
lda #<Header
|
lda #<Header
|
||||||
ldx #>Header
|
ldx #>Header
|
||||||
jsr pushax
|
jsr pushax
|
||||||
lda #O65_HDR_SIZE
|
lda #O65_HDR_SIZE
|
||||||
jsr pusha0 ; Always less than 256
|
ldx #0 ; Always less than 256
|
||||||
jsr ReadAndCheckError ; Bails out in case of errors
|
jsr ReadAndCheckError ; Bails out in case of errors
|
||||||
|
|
||||||
; We read the o65 header successfully. Validate it.
|
; We read the o65 header successfully. Validate it.
|
||||||
@ -483,15 +496,14 @@ GotMem: lda Module
|
|||||||
|
|
||||||
; Load code and data segment into memory. The sum of the sizes of
|
; Load code and data segment into memory. The sum of the sizes of
|
||||||
; code+data segment is still in TPtr.
|
; code+data segment is still in TPtr.
|
||||||
; C->read (C, C->module, H.tlen + H.dlen)
|
; C->read (C->callerdata, C->module, H.tlen + H.dlen)
|
||||||
|
|
||||||
jsr PushCtrl
|
jsr PushCallerData
|
||||||
lda Module
|
lda Module
|
||||||
ldx Module+1
|
ldx Module+1
|
||||||
jsr pushax
|
jsr pushax
|
||||||
lda TPtr
|
lda TPtr
|
||||||
ldx TPtr+1
|
ldx TPtr+1
|
||||||
jsr pushax
|
|
||||||
jsr ReadAndCheckError ; Bails out in case of errors
|
jsr ReadAndCheckError ; Bails out in case of errors
|
||||||
|
|
||||||
; We've got the code and data segments in memory. Next section contains
|
; We've got the code and data segments in memory. Next section contains
|
||||||
|
Loading…
x
Reference in New Issue
Block a user