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

38
asminc/agat.inc Normal file
View File

@@ -0,0 +1,38 @@
;-----------------------------------------------------------------------------
; Zero page stuff
WNDLFT := $20 ; Text window left
WNDWDTH := $21 ; Text window width
WNDTOP := $22 ; Text window top
WNDBTM := $23 ; Text window bottom+1
CH := $24 ; Cursor horizontal position
CV := $25 ; Cursor vertical position
BASL := $28 ; Text base address low
BASH := $29 ; Text base address high
CURSOR := $2D ; Cursor character
TATTR := $32 ; Text attributes
PROMPT := $33 ; Used by GETLN
VCOUT := $36 ; COUT Subroutine Vector
VCIN := $38 ; CIN Subroutine Vector
RNDL := $4E ; Random counter low
RNDH := $4F ; Random counter high
HIMEM := $73 ; Highest available memory address+1
;-----------------------------------------------------------------------------
; Vectors
BRKVec := $03F0 ; Break vector
SOFTEV := $03F2 ; Vector for warm start
PWREDUP := $03F4 ; This must be = EOR #$A5 of SOFTEV+1
;-----------------------------------------------------------------------------
; Hardware
; Keyboard input
KBD := $C000 ; Read keyboard
KBDSTRB := $C010 ; Clear keyboard strobe
; Game controller
BUTN0 := $C061 ; Open-Apple Key
BUTN1 := $C062 ; Closed-Apple Key

44
cfg/agat.cfg Normal file
View File

@@ -0,0 +1,44 @@
# Default configuration
FEATURES {
STARTADDRESS: default = $1903;
}
SYMBOLS {
__EXEHDR__: type = import;
__FILETYPE__: type = weak, value = $0006; # file type
__STACKSIZE__: type = weak, value = $0400; # 1k stack
__HIMEM__: type = weak, value = $C000; # Presumed RAM end
}
MEMORY {
ZP: file = "", define = yes, start = $0080, size = $001A;
HEADER: file = %O, start = %S - $003A, size = $003A;
MAIN: file = %O, define = yes, start = %S, size = __HIMEM__ - %S;
BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
EXEHDR: load = HEADER, type = ro, optional = yes;
STARTUP: load = MAIN, type = ro, optional = yes;
LOWCODE: load = MAIN, type = ro, optional = yes;
CODE: load = MAIN, type = ro;
RODATA: load = MAIN, type = ro;
DATA: load = MAIN, type = rw;
INIT: load = MAIN, type = rw, optional = yes;
ONCE: load = MAIN, type = ro, define = yes;
BSS: load = BSS, type = bss, define = yes;
}
FEATURES {
CONDES: type = constructor,
label = __CONSTRUCTOR_TABLE__,
count = __CONSTRUCTOR_COUNT__,
segment = ONCE;
CONDES: type = destructor,
label = __DESTRUCTOR_TABLE__,
count = __DESTRUCTOR_COUNT__,
segment = RODATA;
CONDES: type = interruptor,
label = __INTERRUPTOR_TABLE__,
count = __INTERRUPTOR_COUNT__,
segment = RODATA,
import = __CALLIRQ__;
}

67
include/agat.h Normal file
View File

@@ -0,0 +1,67 @@
#ifndef _AGAT_H
#define _AGAT_H
/* Check for errors */
#if !defined(__AGAT__)
# error This module may only be used when compiling for the Agat!
#endif
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Color defines */
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_GREEN 0x02
#define COLOR_YELLOW 0x03
#define COLOR_BLUE 0x04
#define COLOR_MAGENTA 0x05
#define COLOR_CYAN 0x06
#define COLOR_WHITE 0x07
/* Characters codes */
#define CH_ENTER 0x0D
#define CH_ESC 0x1B
#define CH_CURS_LEFT 0x08
#define CH_CURS_RIGHT 0x15
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x20
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x40
#define JOY_BTN_2_MASK 0x80
/* Return codes for get_ostype */
#define AGAT_UNKNOWN 0x00
#define AGAT_7 0x10 /* Agat 7 */
#define AGAT_9 0x20 /* Agat 9 */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
unsigned char get_ostype (void);
/* Get the machine type. Returns one of the AGAT_xxx codes. */
void rebootafterexit (void);
/* Reboot machine after program termination has completed. */
/* The following #defines will cause the matching functions calls in conio.h
** to be overlaid by macros with the same names, saving the function call
** overhead.
*/
#define _bgcolor(color) COLOR_BLACK
#define _bordercolor(color) COLOR_BLACK
/* End of agat.h */
#endif //_AGAT_H

View File

@@ -15,7 +15,8 @@ CBMS = c128 \
GEOS = geos-apple \ GEOS = geos-apple \
geos-cbm geos-cbm
TARGETS = apple2 \ TARGETS = agat \
apple2 \
apple2enh \ apple2enh \
atari \ atari \
atarixl \ 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

View File

@@ -350,6 +350,10 @@ static void SetSys (const char* Sys)
NewSymbol ("__RP6502__", 1); NewSymbol ("__RP6502__", 1);
break; break;
case TGT_AGAT:
NewSymbol ("__AGAT__", 1);
break;
default: default:
AbEnd ("Invalid target name: '%s'", Sys); AbEnd ("Invalid target name: '%s'", Sys);

View File

@@ -306,6 +306,10 @@ static void SetSys (const char* Sys)
case TGT_RP6502: case TGT_RP6502:
DefineNumericMacro ("__RP6502__", 1); DefineNumericMacro ("__RP6502__", 1);
break; break;
case TGT_AGAT:
DefineNumericMacro ("__AGAT__", 1);
break;
default: default:
AbEnd ("Unknown target system '%s'", Sys); AbEnd ("Unknown target system '%s'", Sys);

View File

@@ -129,7 +129,25 @@ static const unsigned char CTPET[256] = {
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
}; };
/* Translation table KOI8-R -> Agat-9 */
static unsigned char CTAgat[256] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
0x1B,0x5C,0x10,0x12,0x1D,0x1F,0x13,0x1C,0x11,0x1E,0x14,0x8B,0x8C,0x8D,0x8E,0x8F,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
0xA0,0xA1,0xA2,0x0F,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0xB0,0xB1,0xB2,0x9F,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
};
/* One entry in the target map */ /* One entry in the target map */
typedef struct TargetEntry TargetEntry; typedef struct TargetEntry TargetEntry;
@@ -142,6 +160,7 @@ struct TargetEntry {
** Allows multiple entries for one target ID (target name aliases). ** Allows multiple entries for one target ID (target name aliases).
*/ */
static const TargetEntry TargetMap[] = { static const TargetEntry TargetMap[] = {
{ "agat", TGT_AGAT },
{ "apple2", TGT_APPLE2 }, { "apple2", TGT_APPLE2 },
{ "apple2enh", TGT_APPLE2ENH }, { "apple2enh", TGT_APPLE2ENH },
{ "atari", TGT_ATARI }, { "atari", TGT_ATARI },
@@ -223,6 +242,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = {
{ "sym1", CPU_6502, BINFMT_BINARY, CTNone }, { "sym1", CPU_6502, BINFMT_BINARY, CTNone },
{ "kim1", CPU_6502, BINFMT_BINARY, CTNone }, { "kim1", CPU_6502, BINFMT_BINARY, CTNone },
{ "rp6502", CPU_65C02, BINFMT_BINARY, CTNone }, { "rp6502", CPU_65C02, BINFMT_BINARY, CTNone },
{ "agat", CPU_6502, BINFMT_BINARY, CTAgat },
}; };
/* Target system */ /* Target system */

View File

@@ -89,6 +89,7 @@ typedef enum {
TGT_SYM1, TGT_SYM1,
TGT_KIM1, TGT_KIM1,
TGT_RP6502, TGT_RP6502,
TGT_AGAT,
TGT_COUNT /* Number of target systems */ TGT_COUNT /* Number of target systems */
} target_t; } target_t;