2009-09-22 17:29:49 +00:00
|
|
|
;
|
|
|
|
; Oliver Schmidt, 15.09.2009
|
|
|
|
;
|
|
|
|
; ProDOS 8 I/O buffer management for memory between
|
|
|
|
; location $0800 and the cc65 program start address
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.constructor initiobuf
|
|
|
|
.export iobuf_alloc, iobuf_free
|
|
|
|
.import __STARTUP_RUN__
|
|
|
|
.import incsp2, popax
|
2009-09-22 17:29:49 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "../filedes.inc"
|
2009-09-22 17:29:49 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "INIT"
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
initiobuf:
|
|
|
|
; Convert end address highbyte to table index
|
2012-06-16 22:58:03 +00:00
|
|
|
lda #>__STARTUP_RUN__
|
2009-09-22 17:29:49 +00:00
|
|
|
sec
|
|
|
|
sbc #>$0800
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
|
|
|
|
; Mark all remaining table entries as used
|
|
|
|
tax
|
|
|
|
lda #$FF
|
2009-09-26 21:32:05 +00:00
|
|
|
: cpx #MAX_FDS
|
|
|
|
bcc :+
|
|
|
|
rts
|
2009-09-22 17:29:49 +00:00
|
|
|
: sta table,x
|
|
|
|
inx
|
2009-09-26 21:32:05 +00:00
|
|
|
bne :-- ; Branch always
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
iobuf_alloc:
|
|
|
|
; Get and save "memptr"
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr incsp2
|
|
|
|
jsr popax
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
; Search table for free entry
|
|
|
|
ldx #$00
|
|
|
|
: lda table,x
|
|
|
|
beq :+
|
|
|
|
inx
|
|
|
|
cpx #MAX_FDS
|
|
|
|
bcc :-
|
|
|
|
lda #ENOMEM
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Mark table entry as used
|
|
|
|
: lda #$FF
|
|
|
|
sta table,x
|
|
|
|
|
|
|
|
; Convert table index to address hibyte
|
|
|
|
txa
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
clc
|
|
|
|
adc #>$0800
|
|
|
|
|
|
|
|
; Store address in "memptr"
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #$01
|
|
|
|
sta (ptr1),y
|
|
|
|
dey
|
|
|
|
tya
|
|
|
|
sta (ptr1),y
|
2009-09-22 17:29:49 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
iobuf_free:
|
|
|
|
; Convert address hibyte to table index
|
|
|
|
txa
|
|
|
|
sec
|
|
|
|
sbc #>$0800
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
|
|
|
|
; Mark table entry as free
|
|
|
|
tax
|
|
|
|
lda #$00
|
|
|
|
sta table,x
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
table: .res MAX_FDS
|