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
|
2018-05-21 11:07:26 +00:00
|
|
|
.import __MAIN_START__
|
2018-05-20 13:30:18 +00:00
|
|
|
.import incsp2, popptr1
|
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
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
initiobuf:
|
|
|
|
; Convert end address highbyte to table index
|
2018-05-21 11:07:26 +00:00
|
|
|
lda #>__MAIN_START__
|
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
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1
|
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
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2016-03-16 15:28:32 +00:00
|
|
|
.data
|
2009-09-22 17:29:49 +00:00
|
|
|
|
|
|
|
table: .res MAX_FDS
|