Initial Agat support

This commit is contained in:
Konstantin
2025-06-04 22:51:17 +03:00
parent 58171691d0
commit de524a6561
27 changed files with 735 additions and 2 deletions

View File

@@ -15,7 +15,8 @@ CBMS = c128 \
GEOS = geos-apple \
geos-cbm
TARGETS = apple2 \
TARGETS = agat \
apple2 \
apple2enh \
atari \
atarixl \

113
libsrc/agat/break.s Normal file
View File

@@ -0,0 +1,113 @@
;
; Ullrich von Bassewitz, 27.09.1998
; Oleg A. Odintsov, Moscow, 2024
;
; void __fastcall__ set_brk (unsigned Addr);
; void reset_brk (void);
;
.export _set_brk, _reset_brk
.destructor _reset_brk
; Be sure to export the following variables absolute
.export _brk_a: abs, _brk_x: abs, _brk_y: abs
.export _brk_sr: abs, _brk_pc: abs
.include "agat.inc"
_brk_a = $45
_brk_x = $46
_brk_y = $47
_brk_sr = $48
_brk_sp = $49
_brk_pc = $3A
.bss
oldvec: .res 2 ; Old vector
.data
uservec: jmp $FFFF ; Patched at runtime
.code
; Set the break vector
.proc _set_brk
sta uservec+1
stx uservec+2 ; Set the user vector
lda oldvec
ora oldvec+1 ; Did we save the vector already?
bne L1 ; Jump if we installed the handler already
lda BRKVec
sta oldvec
lda BRKVec+1
sta oldvec+1 ; Save the old vector
L1: lda #<brk_handler ; Set the break vector to our routine
ldx #>brk_handler
sta BRKVec
stx BRKVec+1
rts
.endproc
; Reset the break vector
.proc _reset_brk
lda oldvec
ldx oldvec+1
beq @L9 ; Jump if vector not installed
sta BRKVec
stx BRKVec+1
lda #$00
sta oldvec ; Clear the old vector
stx oldvec+1
@L9: rts
.endproc
; Break handler, called if a break occurs
.proc brk_handler
sec
lda _brk_pc
sbc #$02 ; Point to start of brk
sta _brk_pc
lda _brk_pc+1
sbc #$00
sta _brk_pc+1
clc
lda _brk_sp
adc #$04 ; Adjust stack pointer
sta _brk_sp
lda _brk_sr ; Clear brk
and #$EF
sta _brk_sr
jsr uservec ; Call the user's routine
lda _brk_pc+1
pha
lda _brk_pc
pha
lda _brk_sr
pha
ldx _brk_x
ldy _brk_y
lda _brk_a
rti ; Jump back...
.endproc

17
libsrc/agat/cclear.s Normal file
View File

@@ -0,0 +1,17 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; void __fastcall__ cclear (unsigned char length);
;
.export _cclear
.import COUT
.include "zeropage.inc"
_cclear:
sta ptr1
lda #$A0
next: jsr COUT
dec ptr1
bne next
rts

23
libsrc/agat/cgetc.s Normal file
View File

@@ -0,0 +1,23 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; char cgetc (void);
;
.export _cgetc
.import cursor
.include "agat.inc"
_cgetc:
lda #$DF ; _
bit cursor
bne hascur
lda #$00
hascur: sta CURSOR
jsr j1
cmp #$A0
bpl :+
and #$7F
: rts
j1: jmp (VCIN)

10
libsrc/agat/clrscr.s Normal file
View File

@@ -0,0 +1,10 @@
;
; Kevin Ruland
;
; void clrscr (void);
;
.export _clrscr
.import HOME
_clrscr := HOME

21
libsrc/agat/color.s Normal file
View File

@@ -0,0 +1,21 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; unsigned char __fastcall__ textcolor (unsigned char color);
;
.export _textcolor
.include "agat.inc"
_textcolor:
ldx TATTR
eor TATTR
and #$07
eor TATTR
sta TATTR
txa
and #$0F
rts

14
libsrc/agat/cout.s Normal file
View File

@@ -0,0 +1,14 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; COUT routine
;
.export COUT
.include "agat.inc"
COUT:
cmp #$10
bpl out
ora #$80
out: jmp (VCOUT)

45
libsrc/agat/cputc.s Normal file
View File

@@ -0,0 +1,45 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);
; void __fastcall__ cputc (char c);
;
.import COUT
.export _cputcxy, _cputc
.import gotoxy, VTABZ
.include "agat.inc"
_cputcxy:
pha
jsr gotoxy
pla
_cputc:
cmp #$0D
bne notleft
ldy #$00
sty CH
rts
notleft:cmp #$0A
beq newline
putchar:
ldy CH
sta (BASL),Y
iny
lda TATTR
bmi wch
sta (BASL),Y
iny
wch: sty CH
cpy WNDWDTH
bcc noend
ldy #$00
sty CH
newline:inc CV
lda CV
cmp WNDBTM
bcc :+
lda WNDTOP
sta CV
: jmp VTABZ
noend: rts

25
libsrc/agat/crt0.s Normal file
View File

@@ -0,0 +1,25 @@
;
; Startup code for cc65 (Agat version)
;
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import initlib, donelib
.import zerobss, callmain
.import __ONCE_LOAD__, __ONCE_SIZE__ ; Linker generated
.include "zeropage.inc"
.include "agat.inc"
; ------------------------------------------------------------------------
.segment "STARTUP"
lda HIMEM
ldx HIMEM+1
sta sp
stx sp+1
jsr initlib
jsr zerobss
jsr callmain
jsr donelib
rts

40
libsrc/agat/exehdr.s Normal file
View File

@@ -0,0 +1,40 @@
;
; Oliver Schmidt, 2012-06-10
;
; This module supplies an AppleSingle version 2 file header + entry with
; ID 11 according to https://tools.ietf.org/rfc/rfc1740.txt Appendix A.
;
.export __EXEHDR__ : absolute = 1 ; Linker referenced
.import __FILETYPE__ ; Linker generated
.import __MAIN_START__, __MAIN_LAST__ ; Linker generated
; ------------------------------------------------------------------------
; Data Fork
ID01_LENGTH = __MAIN_LAST__ - __MAIN_START__
ID01_OFFSET = ID01 - START
; ProDOS File Info
ID11_LENGTH = ID01 - ID11
ID11_OFFSET = ID11 - START
; ------------------------------------------------------------------------
.segment "EXEHDR"
START: .byte $00, $05, $16, $00 ; Magic number
.byte $00, $02, $00, $00 ; Version number
.res 16 ; Filler
.byte 0, 2 ; Number of entries
.byte 0, 0, 0, 1 ; Entry ID 1 - Data Fork
.byte 0, 0, >ID01_OFFSET, <ID01_OFFSET ; Offset
.byte 0, 0, >ID01_LENGTH, <ID01_LENGTH ; Length
.byte 0, 0, 0, 11 ; Entry ID 11 - ProDOS File Info
.byte 0, 0, >ID11_OFFSET, <ID11_OFFSET ; Offset
.byte 0, 0, >ID11_LENGTH, <ID11_LENGTH ; Length
ID11: .byte 0, %11000011 ; Access - Destroy, Rename, Write, Read
.byte >__FILETYPE__, <__FILETYPE__ ; File Type
.byte 0, 0 ; Auxiliary Type high
.byte >__MAIN_START__, <__MAIN_START__ ; Auxiliary Type low
ID01:

28
libsrc/agat/gotoxy.s Normal file
View File

@@ -0,0 +1,28 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Oleg A. Odintsov, Moscow, 2024
;
; void __fastcall__ gotoxy (unsigned char x, unsigned char y);
; void __fastcall__ gotox (unsigned char x);
;
.export gotoxy, _gotoxy, _gotox
.import popa, VTABZ
.include "agat.inc"
gotoxy:
jsr popa ; Get Y
_gotoxy:
clc
adc WNDTOP
sta CV ; Store Y
jsr VTABZ
jsr popa ; Get X
_gotox:
bit TATTR
bmi t64
asl
t64:
sta CH ; Store X
rts

18
libsrc/agat/gotoy.s Normal file
View File

@@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Oleg A. Odintsov, Moscow, 2024
;
; void __fastcall__ gotoy (unsigned char y);
;
.import VTABZ
.export _gotoy
.include "agat.inc"
_gotoy:
clc
adc WNDTOP
sta CV
jmp VTABZ

15
libsrc/agat/home.s Normal file
View File

@@ -0,0 +1,15 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; HOME routine
;
.export HOME
.import COUT
.include "agat.inc"
HOME:
lda #$8C
jsr COUT
rts

19
libsrc/agat/kbhit.s Normal file
View File

@@ -0,0 +1,19 @@
;
; Kevin Ruland
; Ullrich von Bassewitz, 2005-03-25
; Oleg A. Odintsov, Moscow, 2024
;
; unsigned char kbhit (void);
;
.export _kbhit
.include "agat.inc"
_kbhit:
lda KBD ; Reading KBD checks for keypress
rol ; if high bit is set, key was pressed
lda #$00
tax
rol
rts

18
libsrc/agat/randomize.s Normal file
View File

@@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 07.11.2002
; Oleg A. Odintsov, Moscow, 2024
;
; void _randomize (void);
; /* Initialize the random number generator */
;
.export __randomize
.import _srand
.include "apple2.inc"
__randomize:
ldx RNDH ; Use random value supplied by ROM
lda RNDL
jmp _srand ; Initialize generator

38
libsrc/agat/revers.s Normal file
View File

@@ -0,0 +1,38 @@
;
; Ullrich von Bassewitz, 2005-03-28
; Oleg A. Odintsov, Moscow, 2024
;
; unsigned char __fastcall__ revers (unsigned char onoff)
; unsigned char __fastcall__ flash (unsigned char onoff)
;
.export _revers, _flash
.include "agat.inc"
_revers:
tax
beq noinv
lda TATTR
and #$D7
sta TATTR
rts
noinv:
lda TATTR
ora #$20
sta TATTR
rts
_flash:
tax
beq noflash
lda TATTR
and #$DF
ora #$08
sta TATTR
rts
noflash:
lda TATTR
ora #$20
sta TATTR
rts

24
libsrc/agat/vtabz.s Normal file
View File

@@ -0,0 +1,24 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; VTABZ routine
;
.export VTABZ
.include "agat.inc"
VTABZ:
lda CV
ror
ror
ror
and #$C0
sta BASL
lda CV
lsr
lsr
eor BASH
and #$07
eor BASH
sta BASH
rts

19
libsrc/agat/wherex.s Normal file
View File

@@ -0,0 +1,19 @@
;
; Kevin Ruland
; Oleg A. Odintsov, Moscow, 2024
;
; unsigned char wherex (void);
;
.export _wherex
.include "agat.inc"
_wherex:
lda CH
bit TATTR
bmi t64
lsr
t64:
ldx #$00
rts

17
libsrc/agat/wherey.s Normal file
View File

@@ -0,0 +1,17 @@
;
; Kevin Ruland
; Oleg A. Odintsov, Moscow, 2024
;
; unsigned char wherey (void);
;
.export _wherey
.include "agat.inc"
_wherey:
lda CV
sec
sbc WNDTOP
ldx #$00
rts

50
libsrc/agat/write.s Normal file
View File

@@ -0,0 +1,50 @@
;
; Oleg A. Odintsov, Moscow, 2024
;
; int __fastcall__ write (int fd, const void* buf, unsigned count);
;
.export _write
.import popax, popptr1
.import COUT
.include "zeropage.inc"
_write:
sta ptr2
stx ptr2+1
jsr popptr1
jsr popax
; Check for zero count
ora ptr2
beq done
; Get char from buf
next: ldy #$00
lda (ptr1),y
; Replace '\n' with '\r'
cmp #$0A
bne output
lda #$8D
; Set hi bit and write to device
output:
jsr COUT ; Preserves X and Y
; Increment pointer
inc ptr1
bne :+
inc ptr1+1
; Decrement count
: dec ptr2
bne next
dec ptr2+1
bpl next
; Return success
done: lda #$00
rts