From de524a6561a86e218225f3b21e3ca5881e4a2861 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 4 Jun 2025 22:51:17 +0300 Subject: [PATCH 01/12] Initial Agat support --- asminc/agat.inc | 38 ++++++++++++++ cfg/agat.cfg | 44 ++++++++++++++++ include/agat.h | 67 ++++++++++++++++++++++++ libsrc/Makefile | 3 +- libsrc/agat/break.s | 113 ++++++++++++++++++++++++++++++++++++++++ libsrc/agat/cclear.s | 17 ++++++ libsrc/agat/cgetc.s | 23 ++++++++ libsrc/agat/clrscr.s | 10 ++++ libsrc/agat/color.s | 21 ++++++++ libsrc/agat/cout.s | 14 +++++ libsrc/agat/cputc.s | 45 ++++++++++++++++ libsrc/agat/crt0.s | 25 +++++++++ libsrc/agat/exehdr.s | 40 ++++++++++++++ libsrc/agat/gotoxy.s | 28 ++++++++++ libsrc/agat/gotoy.s | 18 +++++++ libsrc/agat/home.s | 15 ++++++ libsrc/agat/kbhit.s | 19 +++++++ libsrc/agat/randomize.s | 18 +++++++ libsrc/agat/revers.s | 38 ++++++++++++++ libsrc/agat/vtabz.s | 24 +++++++++ libsrc/agat/wherex.s | 19 +++++++ libsrc/agat/wherey.s | 17 ++++++ libsrc/agat/write.s | 50 ++++++++++++++++++ src/ca65/main.c | 4 ++ src/cc65/main.c | 4 ++ src/common/target.c | 22 +++++++- src/common/target.h | 1 + 27 files changed, 735 insertions(+), 2 deletions(-) create mode 100644 asminc/agat.inc create mode 100644 cfg/agat.cfg create mode 100644 include/agat.h create mode 100644 libsrc/agat/break.s create mode 100644 libsrc/agat/cclear.s create mode 100644 libsrc/agat/cgetc.s create mode 100644 libsrc/agat/clrscr.s create mode 100644 libsrc/agat/color.s create mode 100644 libsrc/agat/cout.s create mode 100644 libsrc/agat/cputc.s create mode 100644 libsrc/agat/crt0.s create mode 100644 libsrc/agat/exehdr.s create mode 100644 libsrc/agat/gotoxy.s create mode 100644 libsrc/agat/gotoy.s create mode 100644 libsrc/agat/home.s create mode 100644 libsrc/agat/kbhit.s create mode 100644 libsrc/agat/randomize.s create mode 100644 libsrc/agat/revers.s create mode 100644 libsrc/agat/vtabz.s create mode 100644 libsrc/agat/wherex.s create mode 100644 libsrc/agat/wherey.s create mode 100644 libsrc/agat/write.s diff --git a/asminc/agat.inc b/asminc/agat.inc new file mode 100644 index 000000000..84d21dbc2 --- /dev/null +++ b/asminc/agat.inc @@ -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 diff --git a/cfg/agat.cfg b/cfg/agat.cfg new file mode 100644 index 000000000..1a740cfc7 --- /dev/null +++ b/cfg/agat.cfg @@ -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__; +} diff --git a/include/agat.h b/include/agat.h new file mode 100644 index 000000000..a8ed98bb0 --- /dev/null +++ b/include/agat.h @@ -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 diff --git a/libsrc/Makefile b/libsrc/Makefile index 8a4f11414..2f1b604d7 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -15,7 +15,8 @@ CBMS = c128 \ GEOS = geos-apple \ geos-cbm -TARGETS = apple2 \ +TARGETS = agat \ + apple2 \ apple2enh \ atari \ atarixl \ diff --git a/libsrc/agat/break.s b/libsrc/agat/break.s new file mode 100644 index 000000000..d46679ba2 --- /dev/null +++ b/libsrc/agat/break.s @@ -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 + 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 + diff --git a/libsrc/agat/cclear.s b/libsrc/agat/cclear.s new file mode 100644 index 000000000..65ae10049 --- /dev/null +++ b/libsrc/agat/cclear.s @@ -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 diff --git a/libsrc/agat/cgetc.s b/libsrc/agat/cgetc.s new file mode 100644 index 000000000..a4b1389d2 --- /dev/null +++ b/libsrc/agat/cgetc.s @@ -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) + diff --git a/libsrc/agat/clrscr.s b/libsrc/agat/clrscr.s new file mode 100644 index 000000000..2fe54607a --- /dev/null +++ b/libsrc/agat/clrscr.s @@ -0,0 +1,10 @@ +; +; Kevin Ruland +; +; void clrscr (void); +; + + .export _clrscr + .import HOME + +_clrscr := HOME diff --git a/libsrc/agat/color.s b/libsrc/agat/color.s new file mode 100644 index 000000000..c68b6c3f6 --- /dev/null +++ b/libsrc/agat/color.s @@ -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 + diff --git a/libsrc/agat/cout.s b/libsrc/agat/cout.s new file mode 100644 index 000000000..30b054b7e --- /dev/null +++ b/libsrc/agat/cout.s @@ -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) diff --git a/libsrc/agat/cputc.s b/libsrc/agat/cputc.s new file mode 100644 index 000000000..b30b6c45c --- /dev/null +++ b/libsrc/agat/cputc.s @@ -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 diff --git a/libsrc/agat/crt0.s b/libsrc/agat/crt0.s new file mode 100644 index 000000000..d678a79c8 --- /dev/null +++ b/libsrc/agat/crt0.s @@ -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 diff --git a/libsrc/agat/exehdr.s b/libsrc/agat/exehdr.s new file mode 100644 index 000000000..72ea390e9 --- /dev/null +++ b/libsrc/agat/exehdr.s @@ -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_LENGTH, ID11_OFFSET, ID11_LENGTH, __FILETYPE__, <__FILETYPE__ ; File Type + .byte 0, 0 ; Auxiliary Type high + .byte >__MAIN_START__, <__MAIN_START__ ; Auxiliary Type low +ID01: diff --git a/libsrc/agat/gotoxy.s b/libsrc/agat/gotoxy.s new file mode 100644 index 000000000..2f9580c91 --- /dev/null +++ b/libsrc/agat/gotoxy.s @@ -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 diff --git a/libsrc/agat/gotoy.s b/libsrc/agat/gotoy.s new file mode 100644 index 000000000..f4a8a4c4e --- /dev/null +++ b/libsrc/agat/gotoy.s @@ -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 + + diff --git a/libsrc/agat/home.s b/libsrc/agat/home.s new file mode 100644 index 000000000..d3f000d25 --- /dev/null +++ b/libsrc/agat/home.s @@ -0,0 +1,15 @@ +; +; Oleg A. Odintsov, Moscow, 2024 +; +; HOME routine +; + + .export HOME + .import COUT + + .include "agat.inc" + +HOME: + lda #$8C + jsr COUT + rts diff --git a/libsrc/agat/kbhit.s b/libsrc/agat/kbhit.s new file mode 100644 index 000000000..f2bc4fc9f --- /dev/null +++ b/libsrc/agat/kbhit.s @@ -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 diff --git a/libsrc/agat/randomize.s b/libsrc/agat/randomize.s new file mode 100644 index 000000000..914f40634 --- /dev/null +++ b/libsrc/agat/randomize.s @@ -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 + diff --git a/libsrc/agat/revers.s b/libsrc/agat/revers.s new file mode 100644 index 000000000..ceca7cf5b --- /dev/null +++ b/libsrc/agat/revers.s @@ -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 diff --git a/libsrc/agat/vtabz.s b/libsrc/agat/vtabz.s new file mode 100644 index 000000000..a711a87c9 --- /dev/null +++ b/libsrc/agat/vtabz.s @@ -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 diff --git a/libsrc/agat/wherex.s b/libsrc/agat/wherex.s new file mode 100644 index 000000000..b6d277680 --- /dev/null +++ b/libsrc/agat/wherex.s @@ -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 diff --git a/libsrc/agat/wherey.s b/libsrc/agat/wherey.s new file mode 100644 index 000000000..4660a55f9 --- /dev/null +++ b/libsrc/agat/wherey.s @@ -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 diff --git a/libsrc/agat/write.s b/libsrc/agat/write.s new file mode 100644 index 000000000..6ac28f32c --- /dev/null +++ b/libsrc/agat/write.s @@ -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 + diff --git a/src/ca65/main.c b/src/ca65/main.c index f3100162a..c99ce06c6 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -350,6 +350,10 @@ static void SetSys (const char* Sys) NewSymbol ("__RP6502__", 1); break; + case TGT_AGAT: + NewSymbol ("__AGAT__", 1); + break; + default: AbEnd ("Invalid target name: '%s'", Sys); diff --git a/src/cc65/main.c b/src/cc65/main.c index 47435757c..baf6f2f17 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -306,6 +306,10 @@ static void SetSys (const char* Sys) case TGT_RP6502: DefineNumericMacro ("__RP6502__", 1); break; + + case TGT_AGAT: + DefineNumericMacro ("__AGAT__", 1); + break; default: AbEnd ("Unknown target system '%s'", Sys); diff --git a/src/common/target.c b/src/common/target.c index b50478e16..761f7c3fd 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -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, }; - +/* 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 */ typedef struct TargetEntry TargetEntry; @@ -142,6 +160,7 @@ struct TargetEntry { ** Allows multiple entries for one target ID (target name aliases). */ static const TargetEntry TargetMap[] = { + { "agat", TGT_AGAT }, { "apple2", TGT_APPLE2 }, { "apple2enh", TGT_APPLE2ENH }, { "atari", TGT_ATARI }, @@ -223,6 +242,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "sym1", CPU_6502, BINFMT_BINARY, CTNone }, { "kim1", CPU_6502, BINFMT_BINARY, CTNone }, { "rp6502", CPU_65C02, BINFMT_BINARY, CTNone }, + { "agat", CPU_6502, BINFMT_BINARY, CTAgat }, }; /* Target system */ diff --git a/src/common/target.h b/src/common/target.h index 730b8211e..d6c9fc35b 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -89,6 +89,7 @@ typedef enum { TGT_SYM1, TGT_KIM1, TGT_RP6502, + TGT_AGAT, TGT_COUNT /* Number of target systems */ } target_t; From 5ff18c1ebc7179002b9be74262ea536d968ffaea Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 4 Jun 2025 23:11:13 +0300 Subject: [PATCH 02/12] Updates --- asminc/agat.inc | 1 + include/agat.h | 12 ++++++---- libsrc/agat/crt0.s | 57 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/asminc/agat.inc b/asminc/agat.inc index 84d21dbc2..b96d31834 100644 --- a/asminc/agat.inc +++ b/asminc/agat.inc @@ -22,6 +22,7 @@ HIMEM := $73 ; Highest available memory address+1 ;----------------------------------------------------------------------------- ; Vectors +DOSWARM := $03D0 ; DOS warmstart vector BRKVec := $03F0 ; Break vector SOFTEV := $03F2 ; Vector for warm start PWREDUP := $03F4 ; This must be = EOR #$A5 of SOFTEV+1 diff --git a/include/agat.h b/include/agat.h index a8ed98bb0..6333170c7 100644 --- a/include/agat.h +++ b/include/agat.h @@ -24,10 +24,14 @@ #define COLOR_WHITE 0x07 /* Characters codes */ -#define CH_ENTER 0x0D -#define CH_ESC 0x1B -#define CH_CURS_LEFT 0x08 -#define CH_CURS_RIGHT 0x15 +#define CH_CTRL_C 0x03 +#define CH_ENTER 0x0D +#define CH_ESC 0x1B +#define CH_CURS_LEFT 0x08 +#define CH_CURS_RIGHT 0x15 +#define CH_CURS_UP 0x19 +#define CH_CURS_DOWN 0x1A +#define CH_ESC 0x1B /* Masks for joy_read */ diff --git a/libsrc/agat/crt0.s b/libsrc/agat/crt0.s index d678a79c8..9f8993332 100644 --- a/libsrc/agat/crt0.s +++ b/libsrc/agat/crt0.s @@ -3,6 +3,7 @@ ; .export __STARTUP__ : absolute = 1 ; Mark as startup + .export _exit .import initlib, donelib .import zerobss, callmain @@ -14,12 +15,60 @@ ; ------------------------------------------------------------------------ .segment "STARTUP" + jsr init + jsr zerobss + jsr callmain +_exit: ldx #exit + jsr reset + jsr donelib +exit: ldx #$02 +: lda rvsave,x + sta SOFTEV,x + dex + bpl :- + ldx #zpspace-1 +: lda zpsave,x + sta sp,x + dex + bpl :- + ldx #$FF + txs + jmp DOSWARM + + + + .segment "ONCE" + +init: ldx #zpspace-1 +: lda sp,x + sta zpsave,x + dex + bpl :- + + ldx #$02 +: lda SOFTEV,x + sta rvsave,x + dex + bpl :- + lda HIMEM ldx HIMEM+1 sta sp stx sp+1 - jsr initlib - jsr zerobss - jsr callmain - jsr donelib + ldx #<_exit + lda #>_exit + jsr reset + jmp initlib + + .code + +reset: stx SOFTEV + sta SOFTEV+1 + eor #$A5 + sta PWREDUP rts + + .segment "INIT" +zpsave: .res zpspace +rvsave: .res 3 From 1a109c0b3438928e1dce045799ae678a576584d0 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sat, 7 Jun 2025 12:36:49 +0300 Subject: [PATCH 03/12] Fix codestyle --- include/agat.h | 50 +++++++++++----------- libsrc/agat/cclear.s | 18 ++++---- libsrc/agat/cgetc.s | 29 +++++++------ libsrc/agat/clrscr.s | 4 +- libsrc/agat/color.s | 21 +++++----- libsrc/agat/cout.s | 12 +++--- libsrc/agat/cputc.s | 68 +++++++++++++++--------------- libsrc/agat/crt0.s | 98 ++++++++++++++++++++++---------------------- libsrc/agat/gotoxy.s | 22 +++++----- libsrc/agat/gotoy.s | 16 ++++---- libsrc/agat/home.s | 6 +-- libsrc/agat/revers.s | 46 ++++++++++----------- libsrc/agat/vtabz.s | 32 +++++++-------- libsrc/agat/wherex.s | 12 +++--- 14 files changed, 215 insertions(+), 219 deletions(-) diff --git a/include/agat.h b/include/agat.h index 6333170c7..2cdf24ae6 100644 --- a/include/agat.h +++ b/include/agat.h @@ -14,38 +14,38 @@ /* 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 +#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_CTRL_C 0x03 -#define CH_ENTER 0x0D -#define CH_ESC 0x1B -#define CH_CURS_LEFT 0x08 -#define CH_CURS_RIGHT 0x15 -#define CH_CURS_UP 0x19 -#define CH_CURS_DOWN 0x1A -#define CH_ESC 0x1B +#define CH_CTRL_C 0x03 +#define CH_ENTER 0x0D +#define CH_ESC 0x1B +#define CH_CURS_LEFT 0x08 +#define CH_CURS_RIGHT 0x15 +#define CH_CURS_UP 0x19 +#define CH_CURS_DOWN 0x1A +#define CH_ESC 0x1B /* 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 +#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 */ +#define AGAT_UNKNOWN 0x00 +#define AGAT_7 0x10 /* Agat 7 */ +#define AGAT_9 0x20 /* Agat 9 */ /*****************************************************************************/ diff --git a/libsrc/agat/cclear.s b/libsrc/agat/cclear.s index 65ae10049..dcc5834ad 100644 --- a/libsrc/agat/cclear.s +++ b/libsrc/agat/cclear.s @@ -4,14 +4,14 @@ ; void __fastcall__ cclear (unsigned char length); ; - .export _cclear - .import COUT - .include "zeropage.inc" + .export _cclear + .import COUT + .include "zeropage.inc" _cclear: - sta ptr1 - lda #$A0 -next: jsr COUT - dec ptr1 - bne next - rts + sta ptr1 + lda #$A0 +next: jsr COUT + dec ptr1 + bne next + rts diff --git a/libsrc/agat/cgetc.s b/libsrc/agat/cgetc.s index a4b1389d2..18bba2fd8 100644 --- a/libsrc/agat/cgetc.s +++ b/libsrc/agat/cgetc.s @@ -4,20 +4,19 @@ ; char cgetc (void); ; - .export _cgetc - .import cursor - .include "agat.inc" + .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) - + lda #$DF ; _ + bit cursor + bne hascur + lda #$00 +hascur: sta CURSOR + jsr j1 + cmp #$A0 + bpl :+ + and #$7F +: rts +j1: jmp (VCIN) diff --git a/libsrc/agat/clrscr.s b/libsrc/agat/clrscr.s index 2fe54607a..8b2d7100b 100644 --- a/libsrc/agat/clrscr.s +++ b/libsrc/agat/clrscr.s @@ -4,7 +4,7 @@ ; void clrscr (void); ; - .export _clrscr - .import HOME + .export _clrscr + .import HOME _clrscr := HOME diff --git a/libsrc/agat/color.s b/libsrc/agat/color.s index c68b6c3f6..0992bb860 100644 --- a/libsrc/agat/color.s +++ b/libsrc/agat/color.s @@ -5,17 +5,16 @@ ; - .export _textcolor - .include "agat.inc" + .export _textcolor + .include "agat.inc" _textcolor: - ldx TATTR - eor TATTR - and #$07 - eor TATTR - sta TATTR - txa - and #$0F - rts - + ldx TATTR + eor TATTR + and #$07 + eor TATTR + sta TATTR + txa + and #$0F + rts diff --git a/libsrc/agat/cout.s b/libsrc/agat/cout.s index 30b054b7e..ae9d8a177 100644 --- a/libsrc/agat/cout.s +++ b/libsrc/agat/cout.s @@ -4,11 +4,11 @@ ; COUT routine ; - .export COUT - .include "agat.inc" + .export COUT + .include "agat.inc" COUT: - cmp #$10 - bpl out - ora #$80 -out: jmp (VCOUT) + cmp #$10 + bpl out + ora #$80 +out: jmp (VCOUT) diff --git a/libsrc/agat/cputc.s b/libsrc/agat/cputc.s index b30b6c45c..6bf9b604f 100644 --- a/libsrc/agat/cputc.s +++ b/libsrc/agat/cputc.s @@ -5,41 +5,41 @@ ; void __fastcall__ cputc (char c); ; - .import COUT - .export _cputcxy, _cputc - .import gotoxy, VTABZ - .include "agat.inc" + .import COUT + .export _cputcxy, _cputc + .import gotoxy, VTABZ + .include "agat.inc" _cputcxy: - pha - jsr gotoxy - pla + pha + jsr gotoxy + pla _cputc: - cmp #$0D - bne notleft - ldy #$00 - sty CH - rts -notleft:cmp #$0A - beq newline + 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 + 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 diff --git a/libsrc/agat/crt0.s b/libsrc/agat/crt0.s index 9f8993332..78fef06bc 100644 --- a/libsrc/agat/crt0.s +++ b/libsrc/agat/crt0.s @@ -14,61 +14,61 @@ ; ------------------------------------------------------------------------ - .segment "STARTUP" - jsr init - jsr zerobss - jsr callmain -_exit: ldx #exit - jsr reset - jsr donelib -exit: ldx #$02 -: lda rvsave,x - sta SOFTEV,x - dex - bpl :- - ldx #zpspace-1 -: lda zpsave,x - sta sp,x - dex - bpl :- - ldx #$FF - txs - jmp DOSWARM + .segment "STARTUP" + jsr init + jsr zerobss + jsr callmain +_exit: ldx #exit + jsr reset + jsr donelib +exit: ldx #$02 +: lda rvsave,x + sta SOFTEV,x + dex + bpl :- + ldx #zpspace-1 +: lda zpsave,x + sta sp,x + dex + bpl :- + ldx #$FF + txs + jmp DOSWARM - .segment "ONCE" + .segment "ONCE" -init: ldx #zpspace-1 -: lda sp,x - sta zpsave,x - dex - bpl :- +init: ldx #zpspace-1 +: lda sp,x + sta zpsave,x + dex + bpl :- - ldx #$02 -: lda SOFTEV,x - sta rvsave,x - dex - bpl :- + ldx #$02 +: lda SOFTEV,x + sta rvsave,x + dex + bpl :- - lda HIMEM - ldx HIMEM+1 - sta sp - stx sp+1 - ldx #<_exit - lda #>_exit - jsr reset - jmp initlib + lda HIMEM + ldx HIMEM+1 + sta sp + stx sp+1 + ldx #<_exit + lda #>_exit + jsr reset + jmp initlib - .code + .code -reset: stx SOFTEV - sta SOFTEV+1 - eor #$A5 - sta PWREDUP - rts +reset: stx SOFTEV + sta SOFTEV+1 + eor #$A5 + sta PWREDUP + rts - .segment "INIT" -zpsave: .res zpspace -rvsave: .res 3 + .segment "INIT" +zpsave: .res zpspace +rvsave: .res 3 diff --git a/libsrc/agat/gotoxy.s b/libsrc/agat/gotoxy.s index 2f9580c91..13e7cb747 100644 --- a/libsrc/agat/gotoxy.s +++ b/libsrc/agat/gotoxy.s @@ -12,17 +12,17 @@ .include "agat.inc" gotoxy: - jsr popa ; Get Y + jsr popa ; Get Y _gotoxy: - clc - adc WNDTOP - sta CV ; Store Y - jsr VTABZ - jsr popa ; Get X + clc + adc WNDTOP + sta CV ; Store Y + jsr VTABZ + jsr popa ; Get X _gotox: - bit TATTR - bmi t64 - asl + bit TATTR + bmi t64 + asl t64: - sta CH ; Store X - rts + sta CH ; Store X + rts diff --git a/libsrc/agat/gotoy.s b/libsrc/agat/gotoy.s index f4a8a4c4e..ea0eadbf2 100644 --- a/libsrc/agat/gotoy.s +++ b/libsrc/agat/gotoy.s @@ -5,14 +5,12 @@ ; void __fastcall__ gotoy (unsigned char y); ; - .import VTABZ - .export _gotoy - .include "agat.inc" + .import VTABZ + .export _gotoy + .include "agat.inc" _gotoy: - clc - adc WNDTOP - sta CV - jmp VTABZ - - + clc + adc WNDTOP + sta CV + jmp VTABZ diff --git a/libsrc/agat/home.s b/libsrc/agat/home.s index d3f000d25..5067a782a 100644 --- a/libsrc/agat/home.s +++ b/libsrc/agat/home.s @@ -10,6 +10,6 @@ .include "agat.inc" HOME: - lda #$8C - jsr COUT - rts + lda #$8C + jsr COUT + rts diff --git a/libsrc/agat/revers.s b/libsrc/agat/revers.s index ceca7cf5b..20c1b9bdb 100644 --- a/libsrc/agat/revers.s +++ b/libsrc/agat/revers.s @@ -6,33 +6,33 @@ ; unsigned char __fastcall__ flash (unsigned char onoff) ; - .export _revers, _flash + .export _revers, _flash - .include "agat.inc" + .include "agat.inc" _revers: - tax - beq noinv - lda TATTR - and #$D7 - sta TATTR - rts + tax + beq noinv + lda TATTR + and #$D7 + sta TATTR + rts noinv: - lda TATTR - ora #$20 - sta TATTR - rts + lda TATTR + ora #$20 + sta TATTR + rts _flash: - tax - beq noflash - lda TATTR - and #$DF - ora #$08 - sta TATTR - rts + tax + beq noflash + lda TATTR + and #$DF + ora #$08 + sta TATTR + rts noflash: - lda TATTR - ora #$20 - sta TATTR - rts + lda TATTR + ora #$20 + sta TATTR + rts diff --git a/libsrc/agat/vtabz.s b/libsrc/agat/vtabz.s index a711a87c9..88166eb35 100644 --- a/libsrc/agat/vtabz.s +++ b/libsrc/agat/vtabz.s @@ -4,21 +4,21 @@ ; VTABZ routine ; - .export VTABZ - .include "agat.inc" + .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 + lda CV + ror + ror + ror + and #$C0 + sta BASL + lda CV + lsr + lsr + eor BASH + and #$07 + eor BASH + sta BASH + rts diff --git a/libsrc/agat/wherex.s b/libsrc/agat/wherex.s index b6d277680..a83f7cd75 100644 --- a/libsrc/agat/wherex.s +++ b/libsrc/agat/wherex.s @@ -10,10 +10,10 @@ .include "agat.inc" _wherex: - lda CH - bit TATTR - bmi t64 - lsr + lda CH + bit TATTR + bmi t64 + lsr t64: - ldx #$00 - rts + ldx #$00 + rts From cbf1b1d5a7857e7e3248787f61cf9d9058a784f5 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sat, 7 Jun 2025 14:00:10 +0300 Subject: [PATCH 04/12] Updated translation table --- src/common/target.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/target.c b/src/common/target.c index 761f7c3fd..fc1a9df25 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -138,11 +138,11 @@ static unsigned char CTAgat[256] = { 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, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA0, + 0x1B,0x5C,0x10,0x12,0x1D,0x1F,0x13,0x1C,0x11,0x1E,0x14,0xA0,0x02,0x5F,0xA0,0xA0, + 0xA0,0xA0,0xA0,0xA0,0xA0,0x9E,0x04,0xA0,0x3C,0x3E,0xA0,0xA0,0x30,0x32,0xA0,0x2F, + 0xA0,0xA0,0xA0,0x0F,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0, + 0xA0,0xA0,0xA0,0x9F,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0, 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, From 34daf33d932eaf4f0ea832b7656b591b4b47ee21 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sat, 7 Jun 2025 14:10:50 +0300 Subject: [PATCH 05/12] Remove dangling spaces --- src/ca65/main.c | 2 +- src/cc65/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ca65/main.c b/src/ca65/main.c index c99ce06c6..682e9be7f 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -353,7 +353,7 @@ static void SetSys (const char* Sys) case TGT_AGAT: NewSymbol ("__AGAT__", 1); break; - + default: AbEnd ("Invalid target name: '%s'", Sys); diff --git a/src/cc65/main.c b/src/cc65/main.c index baf6f2f17..f56974361 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -306,7 +306,7 @@ static void SetSys (const char* Sys) case TGT_RP6502: DefineNumericMacro ("__RP6502__", 1); break; - + case TGT_AGAT: DefineNumericMacro ("__AGAT__", 1); break; From 41a82f7165030ec0e0cddf225c720398aab813ec Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 8 Jun 2025 23:20:21 +0300 Subject: [PATCH 06/12] fix codestyle --- libsrc/agat/_scrsize.s | 17 +++++++++++++++++ libsrc/agat/cclear.s | 3 ++- libsrc/agat/cgetc.s | 3 ++- libsrc/agat/cputc.s | 12 ++++++++---- libsrc/agat/crt0.s | 12 ++++++++---- libsrc/agat/randomize.s | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 libsrc/agat/_scrsize.s diff --git a/libsrc/agat/_scrsize.s b/libsrc/agat/_scrsize.s new file mode 100644 index 000000000..f9d7c3785 --- /dev/null +++ b/libsrc/agat/_scrsize.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + + .include "agat.inc" + +screensize: + ldx WNDWDTH + lda WNDBTM + sec + sbc WNDTOP + tay + rts diff --git a/libsrc/agat/cclear.s b/libsrc/agat/cclear.s index dcc5834ad..93a561ef4 100644 --- a/libsrc/agat/cclear.s +++ b/libsrc/agat/cclear.s @@ -11,7 +11,8 @@ _cclear: sta ptr1 lda #$A0 -next: jsr COUT +next: + jsr COUT dec ptr1 bne next rts diff --git a/libsrc/agat/cgetc.s b/libsrc/agat/cgetc.s index 18bba2fd8..839e4314a 100644 --- a/libsrc/agat/cgetc.s +++ b/libsrc/agat/cgetc.s @@ -13,7 +13,8 @@ _cgetc: bit cursor bne hascur lda #$00 -hascur: sta CURSOR +hascur: + sta CURSOR jsr j1 cmp #$A0 bpl :+ diff --git a/libsrc/agat/cputc.s b/libsrc/agat/cputc.s index 6bf9b604f..b8d99aaea 100644 --- a/libsrc/agat/cputc.s +++ b/libsrc/agat/cputc.s @@ -20,7 +20,8 @@ _cputc: ldy #$00 sty CH rts -notleft:cmp #$0A +notleft: + cmp #$0A beq newline putchar: ldy CH @@ -30,16 +31,19 @@ putchar: bmi wch sta (BASL),Y iny -wch:sty CH +wch: + sty CH cpy WNDWDTH bcc noend ldy #$00 sty CH -newline:inc CV +newline: + inc CV lda CV cmp WNDBTM bcc :+ lda WNDTOP sta CV : jmp VTABZ -noend: rts +noend: + rts diff --git a/libsrc/agat/crt0.s b/libsrc/agat/crt0.s index 78fef06bc..41f03b24d 100644 --- a/libsrc/agat/crt0.s +++ b/libsrc/agat/crt0.s @@ -18,11 +18,13 @@ jsr init jsr zerobss jsr callmain -_exit: ldx #exit jsr reset jsr donelib -exit: ldx #$02 +exit: + ldx #$02 : lda rvsave,x sta SOFTEV,x dex @@ -40,7 +42,8 @@ exit: ldx #$02 .segment "ONCE" -init: ldx #zpspace-1 +init: + ldx #zpspace-1 : lda sp,x sta zpsave,x dex @@ -63,7 +66,8 @@ init: ldx #zpspace-1 .code -reset: stx SOFTEV +reset: + stx SOFTEV sta SOFTEV+1 eor #$A5 sta PWREDUP diff --git a/libsrc/agat/randomize.s b/libsrc/agat/randomize.s index 914f40634..9eef16f05 100644 --- a/libsrc/agat/randomize.s +++ b/libsrc/agat/randomize.s @@ -9,7 +9,7 @@ .export __randomize .import _srand - .include "apple2.inc" + .include "agat.inc" __randomize: ldx RNDH ; Use random value supplied by ROM From 4d5a290135950b5f5c97e9d6b9a5a25f992ba98e Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 8 Jun 2025 23:30:34 +0300 Subject: [PATCH 07/12] add docs and readme.md --- README.md | 1 + doc/agat.sgml | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ doc/index.sgml | 3 ++ 3 files changed, 83 insertions(+) create mode 100644 doc/agat.sgml diff --git a/README.md b/README.md index e3f1ab30f..4c1003179 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ the [cc65 web site](https://cc65.github.io): | Dr. Jozo Dujmović | Picocomputer (RP6502) | | Watara | Watura/QuickShot Supervision | | Synertek | SYM-1 | +| USSR | Agat 7/9 | A generic configuration to adapt cc65 to new targets is also around. diff --git a/doc/agat.sgml b/doc/agat.sgml new file mode 100644 index 000000000..1238dd394 --- /dev/null +++ b/doc/agat.sgml @@ -0,0 +1,79 @@ + + +
+Agat-7/9 - specific information for cc65 + +<author><url url="https://sourceforge.net/u/olegodintsov/profile/" name="Oleg A. Odintsov">,<newline> +<url url="mailto:sintechs@gmail.com" name="Konstantin Fedorov"> + +<abstract> +An overview over the Agat-7 and Agat-9 and theirs interfaces to the cc65 C +compiler. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview + +<p>The Agat was a series of 8-bit computers produced in the Soviet Union from 1983 to 1993. +It was based on Apple II architecture with all electronic components made in the Soviet Union except for 6502 microprocessors supplied by UMC (UM6502A). +<p>If compared to Apple II, Agat had many improvements such as color text mode, additional graphic modes and flexible memory controller. +Agat-7 had an Apple II compatibility card called "Module 121", while Agat-9 had a built-in Apple II+ mode activated by soft-switch. +<p>All mass-produced Agat models were disk-based systems, 2K ROM contained only basic machine language monitor and disassembler. +Agat-7 had 140K floppy-drive based on Apple DISK II, while Agat-9 was supplied with 840K drive having its own sector format and controller. + +<sect>Binary format<p> + +The standard binary file format generated by the linker for the Agat target is +an AppleSingle file to be compatible with AppleCommander <url url="https://applecommander.github.io/">. +The default load address is $1903. + + + +<sect>Platform-specific header files<p> + +Programs containing Agat-specific code may use the <tt/agat.h/ or +<tt/agat.inc/ include files. + +<sect>Usefull info<p> + +<sect1>Emulation<p> + +<enum> +<item> Oleg Odintsov's Agat Emulator - <url url="https://agatemulator.sourceforge.net/english.html"> +<item> MAME - <url url="https://www.mamedev.org/"> +</enum> + +<sect1>Links<p> +<enum> +<item> Most informative source on Agat (in russian) - <url url="https://agatcomp.ru"> +<item> Wikipedia - <url url="https://en.wikipedia.org/wiki/Agat_(computer)"> +<item> Controversial article on Agat from <url name="BYTE Magazine November 1984 Vol. 9, No. 12" url="https://archive.org/details/byte-magazine-1984-11/page/n135/mode/2up?view=theater">. +The author reviewed custom-build mockup Agat bearing little relation to even the early Agat systems. +</enum> + + +<sect>License<p> + +This software is provided "as-is", without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated, but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> diff --git a/doc/index.sgml b/doc/index.sgml index 92df5e018..e39fd11b4 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -109,6 +109,9 @@ <descrip> + <tag><htmlurl url="agat.html" name="agat.html"></tag> + Topics specific to the Agat machines. + <tag><htmlurl url="apple2.html" name="apple2.html"></tag> Topics specific to the Apple ][. From fb421d7a81e3cc89f17f26e50621a3382864626f Mon Sep 17 00:00:00 2001 From: Konstantin <sintechs@gmail.com> Date: Sun, 8 Jun 2025 23:44:51 +0300 Subject: [PATCH 08/12] Remove dangling spaces --- doc/agat.sgml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/agat.sgml b/doc/agat.sgml index 1238dd394..ca5338c5f 100644 --- a/doc/agat.sgml +++ b/doc/agat.sgml @@ -18,16 +18,16 @@ compiler. <sect>Overview -<p>The Agat was a series of 8-bit computers produced in the Soviet Union from 1983 to 1993. +<p>The Agat was a series of 8-bit computers produced in the Soviet Union from 1983 to 1993. It was based on Apple II architecture with all electronic components made in the Soviet Union except for 6502 microprocessors supplied by UMC (UM6502A). -<p>If compared to Apple II, Agat had many improvements such as color text mode, additional graphic modes and flexible memory controller. +<p>If compared to Apple II, Agat had many improvements such as color text mode, additional graphic modes and flexible memory controller. Agat-7 had an Apple II compatibility card called "Module 121", while Agat-9 had a built-in Apple II+ mode activated by soft-switch. -<p>All mass-produced Agat models were disk-based systems, 2K ROM contained only basic machine language monitor and disassembler. +<p>All mass-produced Agat models were disk-based systems, 2K ROM contained only basic machine language monitor and disassembler. Agat-7 had 140K floppy-drive based on Apple DISK II, while Agat-9 was supplied with 840K drive having its own sector format and controller. <sect>Binary format<p> -The standard binary file format generated by the linker for the Agat target is +The standard binary file format generated by the linker for the Agat target is an AppleSingle file to be compatible with AppleCommander <url url="https://applecommander.github.io/">. The default load address is $1903. From 1e80269c6b22371927a35ae19803f0b30be261e5 Mon Sep 17 00:00:00 2001 From: Konstantin <sintechs@gmail.com> Date: Mon, 9 Jun 2025 21:14:01 +0300 Subject: [PATCH 09/12] Add comment about why AppleSingle header is needed --- libsrc/agat/exehdr.s | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsrc/agat/exehdr.s b/libsrc/agat/exehdr.s index 72ea390e9..3f3047bf9 100644 --- a/libsrc/agat/exehdr.s +++ b/libsrc/agat/exehdr.s @@ -4,6 +4,9 @@ ; This module supplies an AppleSingle version 2 file header + entry with ; ID 11 according to https://tools.ietf.org/rfc/rfc1740.txt Appendix A. ; +; Agat target uses this header only for compatibility with Apple Commander +; because Agat's 140K disk filesystem is identical to Apple II DOS 3.3 and +; "ac.jar -as" option can be used to import binaries into disk images. .export __EXEHDR__ : absolute = 1 ; Linker referenced .import __FILETYPE__ ; Linker generated From 9afe980124a6ffe349664aa14e7413de1df80166 Mon Sep 17 00:00:00 2001 From: Konstantin <sintechs@gmail.com> Date: Mon, 9 Jun 2025 21:17:47 +0300 Subject: [PATCH 10/12] Add dash for naming consistency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c1003179..891c31e86 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ the [cc65 web site](https://cc65.github.io): | Dr. Jozo Dujmović | Picocomputer (RP6502) | | Watara | Watura/QuickShot Supervision | | Synertek | SYM-1 | -| USSR | Agat 7/9 | +| USSR | Agat-7/9 | A generic configuration to adapt cc65 to new targets is also around. From c28bafa581b6f3b498b9f02868955bee8b4b7723 Mon Sep 17 00:00:00 2001 From: Konstantin <sintechs@gmail.com> Date: Fri, 13 Jun 2025 12:50:39 +0300 Subject: [PATCH 11/12] add chline, cvline functions --- include/agat.h | 9 +++++++-- libsrc/agat/chline.s | 33 +++++++++++++++++++++++++++++++++ libsrc/agat/cputc.s | 19 +++++++++++++++---- libsrc/agat/cvline.s | 29 +++++++++++++++++++++++++++++ libsrc/agat/home.s | 2 +- 5 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 libsrc/agat/chline.s create mode 100644 libsrc/agat/cvline.s diff --git a/include/agat.h b/include/agat.h index 2cdf24ae6..04ec16984 100644 --- a/include/agat.h +++ b/include/agat.h @@ -32,7 +32,12 @@ #define CH_CURS_UP 0x19 #define CH_CURS_DOWN 0x1A #define CH_ESC 0x1B - +#define CH_HLINE 0x1B +#define CH_VLINE 0x5C +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x12 +#define CH_LLCORNER 0x1D +#define CH_LRCORNER 0x1F /* Masks for joy_read */ #define JOY_UP_MASK 0x10 @@ -68,4 +73,4 @@ void rebootafterexit (void); /* End of agat.h */ -#endif //_AGAT_H +#endif diff --git a/libsrc/agat/chline.s b/libsrc/agat/chline.s new file mode 100644 index 000000000..bc95b2a16 --- /dev/null +++ b/libsrc/agat/chline.s @@ -0,0 +1,33 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; Colin Leroy-Mira, 26.05.2025 +; Konstantin Fedorov, 12.06.2025 +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export _chlinexy, _chline, chlinedirect + .import gotoxy, putchar + + .include "zeropage.inc" + +_chlinexy: + pha ; Save the length + jsr gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _chline + +_chline: + ldx #$1B ; horizontal line character + +chlinedirect: + stx tmp1 + cmp #$00 ; Is the length zero? + beq done ; Jump if done + sta tmp2 +: lda tmp1 ; Screen code + jsr putchar ; Direct output + dec tmp2 + bne :- +done: rts + diff --git a/libsrc/agat/cputc.s b/libsrc/agat/cputc.s index b8d99aaea..b82ce22e6 100644 --- a/libsrc/agat/cputc.s +++ b/libsrc/agat/cputc.s @@ -1,12 +1,13 @@ ; ; Oleg A. Odintsov, Moscow, 2024 +; Konstantin Fedorov, 12.06.2025 ; ; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); ; void __fastcall__ cputc (char c); ; .import COUT - .export _cputcxy, _cputc + .export _cputcxy, _cputc, newline, putchar,putchardirect .import gotoxy, VTABZ .include "agat.inc" @@ -15,20 +16,21 @@ _cputcxy: jsr gotoxy pla _cputc: - cmp #$0D + cmp #$0D ; Test for \r = carriage return bne notleft ldy #$00 sty CH rts notleft: - cmp #$0A + cmp #$0A ; Test for \n = line feed beq newline + putchar: ldy CH sta (BASL),Y iny lda TATTR - bmi wch + bmi wch ; Skip if t64 sta (BASL),Y iny wch: @@ -47,3 +49,12 @@ newline: : jmp VTABZ noend: rts + +putchardirect: + ldy CH + sta (BASL),Y + lda TATTR + bmi :+ + iny + sta (BASL),Y +: rts diff --git a/libsrc/agat/cvline.s b/libsrc/agat/cvline.s new file mode 100644 index 000000000..63c0d4daf --- /dev/null +++ b/libsrc/agat/cvline.s @@ -0,0 +1,29 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; Colin Leroy-Mira, 26.05.2025 +; Konstantin Fedorov, 12.06.2025 +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + + .export _cvlinexy, _cvline + .import gotoxy, putchardirect, newline + + .include "zeropage.inc" + +_cvlinexy: + pha ; Save the length + jsr gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cvline + +_cvline: + cmp #$00 ; Is the length zero? + beq done ; Jump if done + sta tmp2 +: lda #$5C ; vertical line character + jsr putchardirect ; Write, no cursor advance + jsr newline ; Advance cursor to next line + dec tmp2 + bne :- +done: rts diff --git a/libsrc/agat/home.s b/libsrc/agat/home.s index 5067a782a..a0434c9bb 100644 --- a/libsrc/agat/home.s +++ b/libsrc/agat/home.s @@ -11,5 +11,5 @@ HOME: lda #$8C - jsr COUT + jmp COUT rts From 8202b520b262cc0f27a4fa48eddc93e07d6d6042 Mon Sep 17 00:00:00 2001 From: Konstantin <sintechs@gmail.com> Date: Fri, 13 Jun 2025 12:51:41 +0300 Subject: [PATCH 12/12] add Agat to samples --- include/target.h | 2 ++ libsrc/agat/_scrsize.s | 12 +++++++++--- samples/Makefile | 6 ++++++ samples/sieve.c | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/target.h b/include/target.h index 7663a39dd..5f9d8859c 100644 --- a/include/target.h +++ b/include/target.h @@ -37,6 +37,8 @@ # include <apple2enh.h> #elif defined(__APPLE2__) # include <apple2.h> +#elif defined(__AGAT__) +# include <agat.h> #elif defined(__ATARI__) # include <atari.h> #elif defined(__ATARI2600__) diff --git a/libsrc/agat/_scrsize.s b/libsrc/agat/_scrsize.s index f9d7c3785..09d7e879f 100644 --- a/libsrc/agat/_scrsize.s +++ b/libsrc/agat/_scrsize.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 26.10.2000 +; Konstantin Fedorov, 12.06.2025 ; ; Screen size variables ; @@ -9,9 +10,14 @@ .include "agat.inc" screensize: - ldx WNDWDTH - lda WNDBTM + lda WNDWDTH + bit TATTR + bmi t64 + lsr +t64: + tax + lda WNDBTM sec - sbc WNDTOP + sbc WNDTOP tay rts diff --git a/samples/Makefile b/samples/Makefile index 3680f542c..295b6883d 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -158,6 +158,11 @@ DIRLIST = tutorial geos atari2600 atari5200 apple2 gamate lynx supervision sym1 # -------------------------------------------------------------------------- # Lists of executables +EXELIST_agat = \ + ascii \ + checkversion \ + hello \ + sieve EXELIST_apple2 = \ ascii \ @@ -390,6 +395,7 @@ all: # -------------------------------------------------------------------------- # List of every supported platform TARGETS := \ + agat \ apple2 \ apple2enh \ atari \ diff --git a/samples/sieve.c b/samples/sieve.c index 7c3b9cd75..5ffc97b62 100644 --- a/samples/sieve.c +++ b/samples/sieve.c @@ -12,7 +12,7 @@ /* Workaround missing clock stuff */ -#ifdef __APPLE2__ +#if defined(__APPLE2__) || defined(__AGAT__) # define clock() 0 # define CLOCKS_PER_SEC 1 #endif