;############################################################################
;#               EhBASIC and ct-BASIC Terminal Defines                      #
;############################################################################

; mit allen Hardware-Adressen und ZeroPage-Belegung
; to be included in main_cm.asm
;
; Konstanten
	.IF LCD320
rowstart  = 1	; erste genutzte Zeile (0=Statuszeile)
rowstotal = 20	; 
colstotal = 40	; 
	.ENDIF
	.IF LCD480
rowstart  = 2	; 
rowstotal = 19	; statt 40, sonst unten schlecht lesbar
colstotal = 60	; 
	.ENDIF
	.IF VGA640
rowstart  = 2	; 
rowstotal = 39	; statt 40, sonst unten schlecht lesbar
colstotal = 80	; 
	.ENDIF


; Farbcodes
red	= 4
green	= 2
blue	= 1
invert	= 8

; Jump Addresses of important ROM routines, matches table in "basic_cm.asm"	
; Vectors
V_Reset		= ROM_start	; $C000, Cold Start reset
V_WARM		= V_Reset+3	; $C003, EhBASIC warm start
V_CLEAR		= V_WARM+3	; $C006, Reset Vars, String Space etc.
	
V_AccToBank 	= V_CLEAR+3	; $C009, Memory Bank Management
V_BankToAcc 	= V_AccToBank+3 

V_TickerDelay 	= V_BankToAcc+3	; VSync delay * Acc
V_Getkey 	= V_TickerDelay+3	; 	
V_Waitkey 	= V_Getkey+3		;   		
V_WriteScreen 	= V_Waitkey+3	; 		
V_WriteAcc 	= V_WriteScreen+3	; 		
V_ReceiveByte 	= V_WriteAcc+3	; über COMCH
V_SendByte 	= V_ReceiveByte+3	; über COMCH
; wichtig für CALL Erweiterungen
V_LAB_SCGB	= V_SendByte+3	; scan BASIC for "," and get Byte in X
V_LAB_SCGI	= V_LAB_SCGB+3	; scan BASIC for "," and get Integer in ItempL/ItempH


;###################################
; 6502 MONITOR defines
;###################################
;
;  local Zero-page variables
;  used by monitor only

Cmdptr         =     $50               ; 2 bytes
Cmdptr_H       =     $51
Startaddr      =     $52               ; 2 bytes
Startaddr_H    =     $53
Addrptr        =     $54               ; 2 bytes
Addrptr_H      =     $55
Hexdigits      =     $56               ; 2 bytes
Hexdigits_H    =     $57
Memptr         =     $58               ; 2 bytes
Memptr_H       =     $59
;
; Local Non-Zero Page Variables
;
;MonBuf  = $0720 ; bis $7CF für Monitor reserviert
buffer         =     MonBuf		; keybd input buffer (127 chrs max)
PCH            =     MonBuf+$80		; hold program counter (need PCH next to PCL for Printreg routine)
PCL            =     MonBuf+$81		;  ""
ACC            =     MonBuf+$82		; hold Accumulator (A)
XREG           =     MonBuf+$83		; hold X register
YREG           =     MonBuf+$84		; hold Y register
SPTR           =     MonBuf+$85		; hold stack pointer
PREG           =     MonBuf+$86		; hold status register (P)
ytemp          =     MonBuf+$87
xtemp          =     MonBuf+$88
atemp          =     MonBuf+$89
xtemp2         =     MonBuf+$8a
ytemp2         =     MonBuf+$8b
Prompt         =     MonBuf+$8c		; 1 byte   
linecnt        =     MonBuf+$8d		; 1 byte
Modejmp        =     MonBuf+$8e		; 1 byte
Hexdigcnt      =     MonBuf+$8f		; 1 byte
OPCtxtptr      =     MonBuf+$90		; 1 byte
Memchr         =     MonBuf+$91		; 1 byte, $07B1


;###################################
;#   CMs ZeroPage for HW drivers   #
;###################################

; $50 to $59 used by monitor also!
; for Acc move from/to (BankPtrL),Y in Bank (AccessBank)
AccessBank	= $46	; 70 dez., Bank für PEEKs/POKEs, auch durch BANK gesetzt
CurrBank 	= $47	; 71 dez., aktuelle Speicherseite durch BANK gesetzt
BankPtr		= $52               ; 2 bytes
BankPtrH	= $53

Omode	= $5A	; Output Mode, 0=Screen Std, $40=Fehlermeldung, $80=AVRCOM
; freie Zeropage in EhBASIC $DE bis $EE
; $DC und $DD für TextPosX/Y
ptrsrc	= $DE	; +1 für Ptr
ptrdest	= $E0	; +1 für Ptr
TextIdx	= ptrsrc;
ScreenIdx	= ptrsrc+1;

work	= $E2
xsave	= $E3
ysave	= $E4
asave	= $E5
irqa	= $E6
RunFlag = $E7	; ist 0 wenn immediate Mode
iRxPtr	= $E8	; Lese-Pointer auf eingetroffene Daten
RxPtr   = $E9	; IRQ-SChreibpointer auf eingetroffene Daten
iKbdPtr	= $EA	; Lese-Pointer auf eingetroffene Daten
KbdPtr  = $EB	; IRQ-Schreibpointer auf eingetroffene Daten


;###################################
;# IO-Bereich $3xx innerhalb FPGA  #
;###################################

; Hardware-Register, meist Write Only

syncFlgs= $0302 ; PlotDone Bit 7 und PlotSync (ex VSYNC) Bit 6
GDone	= $0302 ; Lesen:  GDONE (MSBit 7)
bank	= $0303 ; Bank Select, 0=main, $0800..$AFFF

PS2code = $0304 ; PS2-Scancode raw
PS2status = $0305 ; PS2-Status, Bit 7 = TxBusy

SPIkey	= $0307	; Keyboard via SPI


UART1D		= $0310	; KC UART Data Rx/Tx OptoBusCore
UART1RxS	= $0312	; KC UART Rx Status, Bit 7 = data present, Bit 6 = half full
UART1TxS	= $0313	; KC UART Tx Status, Bit 7="1", Bit 6 = full
UART1RxC	= $0314	; KC UART Rx Buffer Clear
UART1TxC	= $0315	; KC UART Tx Buffer Clear
UART_BAUD	= $031E	; KC UART Baudrate Selector, 0=38400, 1=19200, 2=9600 ... 7=300 Bd 
UART_SEL	= $031F	; KC UART Multiplexer UART-Select, 0=OptoBusCore, 1=SerialCore

COMport	= $0309 ; ReceiveByte/PutByte-Port intern an AVR

IRQsrc	= $030D ; Lesen: Interrupt-Quelle und GDONE (MSBit 7)
IRQena	= $030D ; Schreiben: F_INT-Leitung

;NMIack	= $030C ; NMI bestätigen, NMI-Latch zurücksetzen

IRQack	= $030E ; IRQ bestätigen, IRQ-Latch zurücksetzen
IRQclr	= $030F ; IRQ-Source-Latch zurücksetzen

;Neue Grafikregister im GTEXT-Parser
GraphX	= $0320	; X-Koordinatenregister, 0..255, oben links = 0,0
GraphY	= $0321	; Y-Koordinatenregister, 0..191, oben links = 0,0
GmvTrig = $0322	; PLOT Move-Befehl triggern, Daten ignoriert, beliebiger Schreibzugriff
GptTrig = $0323 ; PLOT Point-Befehl triggern, Daten ignoriert
GlnTrig = $0324	; PLOT Line-Befehl triggern, Daten ignoriert
GrcTrig = $0325	; PLOT Rect-Befehl triggern, Daten ignoriert
GflTrig = $0326	; PLOT FillRect-Befehl triggern, Daten ignoriert
Gsmall	= $0327	; Grafik Pixelgröße, 0=DoubleScan (groß), 1=klein
GstartX	= $0328	; Grafik-Fenster Startposition X
GstartY	= $0329	; Grafik-Fenster Startposition Y
GsizeX	= $032A	; Grafik-Fenster Größe X
GsizeY	= $032B	; Grafik-Fenster Größe Y
GridX	= $032C	; Grafik-Fenster Gitterraster Abstand X
GridY	= $032D	; Grafik-Fenster Gitterraster Abstand Y
GFrameC	= $032E	; Grafik-Fenster Hintergrundfarbe 0..7, 8..15 mit Raster und Rand
GcolorP	= $032F	; Grafik-Fenster Punkt- und Linienfarbe

;VGA-Text-Register, auch lesbar ab 2.3
TextX	= $0330	; Textzeiger-Register
TextY	= $0331	; jetzt im GTEXT-Parser
CursorStyle = $0332 ; 0 = aus, Bit 0 = small underline, Bit 1 = blinkend, Bit 2 = Enable
ColorP	= $0333 ; Farb-Byte vom COLOR-Befehl, auch Lesen aktuelle TextXY-Position
TextCols= $0336	; in neuem main.bit nicht mehr nötig
TextWR	= $0337	; Textbyte XY zum Schreiben/Lesen

BtnX	= $0338	; Textzeiger-Register Bigfont/Button
BtnY	= $0339	; jetzt im GTEXT-Parser
BtnWR	= $033A	; Textspeicher Button XY zum Schreiben/Lesen
BtnHilite	= $033B	; jetzt im GTEXT-Parser


MouseStyle = $033D ; 0 = aus, 1 = Zeiger, 2 = Fadenkreuz
MouseX	= $033E	; Maus-Positionsregister, 8.. 174
MouseY	= $033F	; Maus-Positionsregister, 8.. 244

; 4 interne Ports an BASIC_Glue zur internen FPGA-Verwendung
PortIntern0 = $340	; 4 interne Ports an BASIC_Glue
PortIntern1 = $341	; 4 interne Ports an BASIC_Glue
PortIntern2 = $342	; 4 interne Ports an BASIC_Glue
PortIntern3 = $343	; 4 interne Ports an BASIC_Glue

MultA		= $3E8	; WRITE: 16 Bit HW Multiplier Value A LSB POKE 1000,A etc.
MultA_hi	= $3E9	; WRITE: 16 Bit HW Multiplier Value A MSB
MultB		= $3EA	; WRITE: 16 Bit HW Multiplier Value B LSB
MultB_hi	= $3EB	; WRITE: 16 Bit HW Multiplier Value B MSB
MultResult	= $3E8	; READ: 32 Bit Result 4 Bytes $3E8 (LSB) ..$3EB (MSB)

;###################################
;#     Buffer-Bereich im RAM       #
;###################################

RxBuf	= $0400 ; Buffer für ReceiveByte-Daten von AVRCOM oder UART
KbdBuf  = $0500 ; Buffer für SPI-Kbd-Daten

;###################################
;#    IO-Bereich extern dekodiert  #
;###################################

; IO-Range extern, innerhalb dessen IO_RDn, IO_WRn bei CPU-Zugriff auf "0" gehen
IOrange	= $0600 ; bis $6FF

;###################################
;#     Scratch-Bereich im RAM      #
;###################################

; internes Scratchpad-RAM

GetbFlg = $0700 ; ist "=" wenn Wert angenommen wird
InsFlg	= $0701	; Insert wenn $20
CapsFlg	= $0702	; UpCase-Konvertierung in BASIC wenn $20
temp	= $0703
xstatus	= $0704	; X save für Status-Routine
ystatus	= $0705	; Y save für Status-Routine

xkey	= $0706	; X save für Keyboard-Routine
ykey	= $0707	; Y save für Keyboard-Routine
irqs	= $0708 ; IRQ-Quelle Kopie
repeat	= $0709	; Autorepeat-Timer
repRate = $070A	; Autorepeat-Rate
Color 	= $070B ; Farb-Byte vom COLOR-Befehl
COMCH	= $070D ; Com-Channel, 0=intern AVR, 1=OptoBusCore, 2=SerCore
COMCHsave	= $070E ; Com-Channel, 0=intern AVR, 1=OptoBusCore, 2=SerCore

Tx0ACK		= $0710 ; COM Tx $80=ACK received, 0 nach CR
ElseFlag 	= $0711 ; Flag nach IF THEN.. für ELSE
LabReqIgnoreChr	= $0712 ; Flag für LABINP=$0A, LABREQ="["
LabReqMainCh	= $0713 ; angeforderter MainCh
LabReqSubCh	= $0714 ; angeforderter SubCh
LabErrFlags	= $0715 ; Fehler bei LAB-Befehl, wird von LABERR zurückgegeben
HashSignIdx	= $0716	; Position nach "#" in Ibuffs
EqualSignIdx	= $0717 ; Position nach "=" in Ibuffs
ColonSignIdx	= $0718 ; Position nach ":" in IbuffsR
FunnyComp	= $0719	; Funny Complement, Startauswahl wenn = $A5, sonst Kaltstart

MonBuf  = $0720 ; bis $7B1 für Monitor reserviert, bereits oben definiert

TextPosX	= $DC	; Letzte Position der Schreibmarke
TextPosY	= $DD

BtnPosX		= $07B6	; Letzte ButtonText-Koordinaten, wird in GetKey/MouseEvent gesetzt
BtnPosY		= $07B7 ; für MouseButtonKey

MouseTextXtemp	= $07BA	; Als Zwischenspeicher für letzte "echte" Textkoordinaten
MouseTextYtemp	= $07BB ; in Mouse-Routinen

MouseButtonsOld = $07BD	; alter Button-Status zum Vergleich
MouseOverlayToggle	= $07BF

MouseSync	= $07C0	; Zähler für Maus-Inaktivität
MouseBufPtr	= $07C1
MouseBuf	= $07C2 ; 3 bis 5 Bytes
MousePosX	= $07CD	; = PEEK(1997), Absolute Maus-Koordinaten, wird von IRQ gesetzt
MousePosY	= $07CE	; = PEEK(1998) 
MouseButtons	= $07CF	; = PEEK(1999) 
MouseTextX	= $07D0	; = PEEK(2000), Absolute Maus-Koordinaten in Text-Reihen/Spalten
MouseTextY	= $07D1	; = PEEK(2001), wird von IRQ gesetzt


Timer60	= $07D2	; = PEEK(2002), NMI-60Hz-Timer, Dekrement mit VSync
TimeOut	= $07D3	; = PEEK(2003), Zählt mit NMI bis auf 0 zurück

; Textfenster erste und letzte Position
TextWinLeft 	= $07D4 ; Textfenster 0..79, 0..40 2004 dez.
TextWinTop 	= $07D5 ; 2005 dez.
TextWinRight	= $07D6 ; 2006 dez.
TextWinBtm 	= $07D7 ; 2007 dez.
; Textfenster-Rand 0..79, 0..40 dez., immer 1 größer/kleiner als TextWin-Werte
BorderLeft 	= $07D8 ; 2008 dez.
BorderTop 	= $07D9 ; 2009 dez.
BorderRight	= $07DA ; 2010 dez.
BorderBtm 	= $07DB ; 2011 dez.

PS2breakFlag	= $07DC ; Bit 7 gesetzt wenn Break-Code vorweggegangen war
PS2shiftFlag	= $07DD	; Shift Bit 7 (MSB)
PS2ctrlFlag	= $07DE	; Control/Strg Bit 7 (MSB)
PS2altFlag	= $07DF	; ALT Bit 7 (MSB)
PS2specialFlag	= $07E0	; E0-Codes, Pfeiltasten usw.
CursorVisible	= $07E1	; Flag für Cursor sichtbar, von CursorOn/Off gesetzt
peekKey		= $07E4 ; letzte gedrückte Taste, PEEK(2020)
peekScancode 	= $07E5 ; letzter PS/2-Scancode, PEEK(2021)
peekEvent 	= $07E6	; Event liegt an wenn >0, PEEK(2022)

PS2sendStackPtr	= $07E7	; Anzahl der PS/2-Bytes zum Gerät (max. 5)
PS2sendStack 	= $07E8	; 5 Bytes an PS/2, wird von oben abgearbeitet
; bis $7EC
KeyEventCode 	= 1	; wird in peekEvent abgelegt wenn Taste gedrückt
MouseEventCode 	= 2	; wird in peekEvent abgelegt wenn Maus bewegt/geklickt

LastPlotColor	=$07ED
LastPlotX	=$07EE	; Letzte Plot-Koordinaten
LastPlotY	=$07EF
scratch	=$07F0		; 16 Bytes weiterer Scratch für PlotLib

;###################################
;#          Video-RAM, ROM         #
;###################################

VRAM	= $B000	; Start des Bildschirmspeichers, 3200 Bytes bei VGA, Rest frei

RAM_base	= $0800	; start of user RAM (set as needed, should be page aligned)
ROM_start	= $C000 ; start location of BASIC ROM (length $2800)
RAM_top		= VRAM	; end of user RAM+1 (set as needed, should be page aligned)
AUX_start	= $BD00 ; freies RAM oberhalb VGA-Text


;###################################
; EhBASIC defines for BASIC Kernal
;###################################

; ZeroPage Belegung

LAB_WARM 	= $00		; BASIC warm start entry point
Wrmjpl 		= LAB_WARM+1	; BASIC warm start vector jump low byte
Wrmjph 		= LAB_WARM+2	; BASIC warm start vector jump high byte

; Diese Jumps können auf eigene Routinen verbogen werden
ZP_Getkey	= $03		; Jump to GetKey für BASIC
GetkeyjpL	= ZP_Getkey+1
GetkeyjpH	= ZP_Getkey+2

ZP_WriteAcc	= $06		; Jump to WriteAcc für BASIC
WritejpL	= ZP_WriteAcc+1
WritejpH	= ZP_WriteAcc+2

; ZP $09 unused

Usrjmp		= $0A		; USR function JMP address
Usrjpl		= Usrjmp+1	; USR function JMP vector low byte
Usrjph		= Usrjmp+2	; USR function JMP vector high byte
Nullct		= $0D		; nulls output after each line
TPos		= $0E		; BASIC terminal position byte
;TWidth		= $0F		; BASIC terminal width byte
Iclim		= $10		; input column limit
Itempl		= $11		; temporary integer low byte
Itemph		= Itempl+1	; temporary integer high byte

nums_1		= Itempl	; number to bin/hex string convert MSB
nums_2		= nums_1+1	; number to bin/hex string convert
nums_3		= nums_1+2	; number to bin/hex string convert LSB

; $50 to $59 used by monitor
Srchc		= $5B		; search character
Temp3		= Srchc		; temp byte used in number routines
Scnquo		= $5C		; scan-between-quotes flag
Asrch		= Scnquo	; alt search character

XOAw_l		= Srchc		; eXclusive OR, OR and AND word low byte
XOAw_h		= Scnquo	; eXclusive OR, OR and AND word high byte

Ibptr		= $5D		; input buffer pointer
Dimcnt		= Ibptr		; # of dimensions
Tindx		= Ibptr		; token index

Defdim		= $5E		; default DIM flag
Dtypef		= $5F		; data type flag, $FF=string, $00=numeric
Oquote		= $60		; open quote flag (b7) (Flag: DATA scan; LIST quote; memory)
Gclctd		= $60		; garbage collected flag
Sufnxf		= $61		; subscript/FNX flag, 1xxx xxx = FN(0xxx xxx)
Imode		= $62		; input mode flag, $00=INPUT, $80=READ

Cflag		= $63		; comparison evaluation flag

TabSiz		= $64		; TAB step size (was input flag)

next_s		= $65		; next descriptor stack address

				; these two bytes form a word pointer to the item
				; currently on top of the descriptor stack
last_sl		= $66		; last descriptor stack address low byte
last_sh		= $67		; last descriptor stack address high byte (always $00)

des_sk		= $68		; descriptor stack start address (temp strings)

;		= $70		; End of descriptor stack

ut1_pl		= $71		; utility pointer 1 low byte
ut1_ph		= ut1_pl+1	; utility pointer 1 high byte
ut2_pl		= $73		; utility pointer 2 low byte
ut2_ph		= ut2_pl+1	; utility pointer 2 high byte

Temp_2		= ut1_pl	; temp byte for block move	

FACt_1		= $75		; FAC temp mantissa1
FACt_2		= FACt_1+1	; FAC temp mantissa2
FACt_3		= FACt_2+1	; FAC temp mantissa3

dims_l		= FACt_2	; array dimension size low byte
dims_h		= FACt_3	; array dimension size high byte

TempB		= $78		; temp page 0 byte

Smeml		= $79		; start of mem low byte		(Start-of-Basic)
Smemh		= Smeml+1	; start of mem high byte	(Start-of-Basic)
Svarl		= $7B		; start of vars low byte	(Start-of-Variables)
Svarh		= Svarl+1	; start of vars high byte	(Start-of-Variables)
Sarryl		= $7D		; var mem end low byte		(Start-of-Arrays)
Sarryh		= Sarryl+1	; var mem end high byte		(Start-of-Arrays)
Earryl		= $7F		; array mem end low byte	(End-of-Arrays)
Earryh		= Earryl+1	; array mem end high byte	(End-of-Arrays)
Sstorl		= $81		; string storage low byte	(String storage (moving down))
Sstorh		= Sstorl+1	; string storage high byte	(String storage (moving down))
Sutill		= $83		; string utility ptr low byte
Sutilh		= Sutill+1	; string utility ptr high byte
Ememl		= $85		; end of mem low byte		(Limit-of-memory)
Ememh		= Ememl+1	; end of mem high byte		(Limit-of-memory)
Clinel		= $87		; current line low byte		(Basic line number)
Clineh		= Clinel+1	; current line high byte	(Basic line number)
Blinel		= $89		; break line low byte		(Previous Basic line number)
Blineh		= Blinel+1	; break line high byte		(Previous Basic line number)

Cpntrl		= $8B		; continue pointer low byte
Cpntrh		= Cpntrl+1	; continue pointer high byte

Dlinel		= $8D		; current DATA line low byte
Dlineh		= Dlinel+1	; current DATA line high byte

Dptrl		= $8F		; DATA pointer low byte
Dptrh		= Dptrl+1	; DATA pointer high byte

Rdptrl		= $91		; read pointer low byte
Rdptrh		= Rdptrl+1	; read pointer high byte

Varnm1		= $93		; current var name 1st byte
Varnm2		= Varnm1+1	; current var name 2nd byte

Cvaral		= $95		; current var address low byte
Cvarah		= Cvaral+1	; current var address high byte

Frnxtl		= $97		; var pointer for FOR/NEXT low byte
Frnxth		= Frnxtl+1	; var pointer for FOR/NEXT high byte

Tidx1		= Frnxtl	; temp line index

Lvarpl		= Frnxtl	; let var pointer low byte
Lvarph		= Frnxth	; let var pointer high byte

prstk		= $99		; precedence stacked flag

comp_f		= $9B		; compare function flag, bits 0,1 and 2 used
				; bit 2 set if >
				; bit 1 set if =
				; bit 0 set if <

func_l		= $9C		; function pointer low byte
func_h		= func_l+1	; function pointer high byte

garb_l		= func_l	; garbage collection working pointer low byte
garb_h		= func_h	; garbage collection working pointer high byte

des_2l		= $9E		; string descriptor_2 pointer low byte
des_2h		= des_2l+1	; string descriptor_2 pointer high byte

g_step		= $A0		; garbage collect step size

Fnxjmp		= $A1		; jump vector for functions
Fnxjpl		= Fnxjmp+1	; functions jump vector low byte
Fnxjph		= Fnxjmp+2	; functions jump vector high byte

g_indx		= Fnxjpl	; garbage collect temp index

FAC2_r		= $A3		; FAC2 rounding byte

Adatal		= $A4		; array data pointer low byte
Adatah		= Adatal+1	; array data pointer high  byte

Nbendl		= Adatal	; new block end pointer low byte
Nbendh		= Adatah	; new block end pointer high  byte

Obendl		= $A6		; old block end pointer low byte
Obendh		= Obendl+1	; old block end pointer high  byte

numexp		= $A8		; string to float number exponent count
expcnt		= $A9		; string to float exponent count

numbit		= numexp	; bit count for array element calculations

numdpf		= $AA		; string to float decimal point flag
expneg		= $AB		; string to float eval exponent -ve flag

Astrtl		= numdpf	; array start pointer low byte
Astrth		= expneg	; array start pointer high  byte

Histrl		= numdpf	; highest string low byte
Histrh		= expneg	; highest string high  byte

Baslnl		= numdpf	; BASIC search line pointer low byte
Baslnh		= expneg	; BASIC search line pointer high  byte

Fvar_l		= numdpf	; find/found variable pointer low byte
Fvar_h		= expneg	; find/found variable pointer high  byte

Ostrtl		= numdpf	; old block start pointer low byte
Ostrth		= expneg	; old block start pointer high  byte

Vrschl		= numdpf	; variable search pointer low byte
Vrschh		= expneg	; variable search pointer high  byte

FAC1_e		= $AC		; FAC1 exponent
FAC1_1		= FAC1_e+1	; FAC1 mantissa1
FAC1_2		= FAC1_e+2	; FAC1 mantissa2
FAC1_3		= FAC1_e+3	; FAC1 mantissa3
FAC1_s		= FAC1_e+4	; FAC1 sign (b7)

str_ln		= FAC1_e	; string length
str_pl		= FAC1_1	; string pointer low byte
str_ph		= FAC1_2	; string pointer high byte

des_pl		= FAC1_2	; string descriptor pointer low byte
des_ph		= FAC1_3	; string descriptor pointer high byte

mids_l		= FAC1_3	; MID$ string temp length byte

negnum		= $B1		; string to float eval -ve flag
numcon		= $B1		; series evaluation constant count

FAC1_o		= $B2		; FAC1 overflow byte

FAC2_e		= $B3		; FAC2 exponent
FAC2_1		= FAC2_e+1	; FAC2 mantissa1
FAC2_2		= FAC2_e+2	; FAC2 mantissa2
FAC2_3		= FAC2_e+3	; FAC2 mantissa3
FAC2_s		= FAC2_e+4	; FAC2 sign (b7)

FAC_sc		= $B8		; FAC sign comparison, Acc#1 vs #2
FAC1_r		= $B9		; FAC1 rounding byte

ssptr_l		= FAC_sc	; string start pointer low byte
ssptr_h		= FAC1_r	; string start pointer high byte

sdescr		= FAC_sc	; string descriptor pointer

csidx		= $BA		; line crunch save index
Asptl		= csidx		; array size/pointer low byte
Aspth		= $BB		; array size/pointer high byte

Btmpl		= Asptl		; BASIC pointer temp low byte
Btmph		= Aspth		; BASIC pointer temp low byte
Cptrl		= Asptl		; BASIC pointer temp low byte
Cptrh		= Aspth		; BASIC pointer temp low byte

Sendl		= Asptl		; BASIC pointer temp low byte
Sendh		= Aspth		; BASIC pointer temp low byte

LAB_IGBY	= $BC		; get next BASIC byte subroutine

LAB_GBYT	= $C2		; get current BASIC byte subroutine
Bpntrl		= $C3		; BASIC execute (get byte) pointer low byte
Bpntrh		= Bpntrl+1	; BASIC execute (get byte) pointer high byte

;		= $D3		; end of get BASIC char subroutine

Rbyte4		= $D4		; extra PRNG byte
Rbyte1		= Rbyte4+1	; most significant PRNG byte
Rbyte2		= Rbyte4+2	; middle PRNG byte
Rbyte3		= Rbyte4+3	; least significant PRNG byte

; IRQ und NMI in dieser Version nicht benutzt, ZP frei von $D8 bis$DD

;NmiBase	= $D8		; NMI handler enabled/setup/triggered flags
				; bit	function
				; ===	========
				; 7	interrupt enabled
				; 6	interrupt setup
				; 5	interrupt happened
;		= $D9		; NMI handler addr low byte
;		= $DA		; NMI handler addr high byte
;IrqBase	= $DB		; IRQ handler enabled/setup/triggered flags
;		= $DC		; IRQ handler addr low byte
;		= $DD		; IRQ handler addr high byte
;
; $DE to $EE used by I/O and LOAD/SAVE
; $DC und $DD für TextPosX/Y

Decss		= $EF		; number to decimal string start
Decssp1		= Decss+1	; number to decimal string start

;			= $FF	; decimal string end

; token values needed for BASIC

; primary command tokens (can start a statement)

TK_END		= $80		; END token
TK_FOR		= TK_END+1	; FOR token
TK_NEXT		= TK_FOR+1	; NEXT token
TK_DATA		= TK_NEXT+1	; DATA token
TK_INPUT	= TK_DATA+1	; INPUT token
TK_DIM		= TK_INPUT+1	; DIM token
TK_READ		= TK_DIM+1	; READ token
TK_LET		= TK_READ+1	; LET token
TK_DEC		= TK_LET+1	; DEC token
TK_GOTO		= TK_DEC+1	; GOTO token
TK_RUN		= TK_GOTO+1	; RUN token
TK_IF		= TK_RUN+1	; IF token
TK_RESTORE	= TK_IF+1	; RESTORE token
TK_GOSUB	= TK_RESTORE+1	; GOSUB token

TK_COLOR	= TK_GOSUB+1	; -cm
TK_CURSXY	= TK_COLOR+1	; -cm
TK_LABCMD	= TK_CURSXY+1	; LABCMD token
TK_ELSE		= TK_LABCMD+1	; new ELSE extension for IF THEN
TK_LABINP	= TK_ELSE+1	; LABINP token; INPUT von c't-Lab
TK_LABOUT	= TK_LABINP+1	; LABOUT token; PRINT an c't-Lab
TK_LABREQ	= TK_LABOUT+1	
	
TK_LABBUS	= TK_LABREQ+1	; Auswahl COM-Schnittstelle	
TK_MACRO	= TK_LABBUS+1		
TK_RENUMBER	= TK_MACRO+1		

TK_RETURN	= TK_RENUMBER+1	; RETURN token
TK_REM		= TK_RETURN+1	; REM token

TK_PLOT		= TK_REM+1	; was STOP token, now PLOT -cm

TK_ON		= TK_PLOT+1	; ON token
TK_BANK		= TK_ON+1	; was NULL token, now BANK switch
TK_INC		= TK_BANK+1	; INC token
TK_WAIT		= TK_INC+1	; WAIT token
TK_LOAD		= TK_WAIT+1	; LOAD token
TK_SAVE		= TK_LOAD+1	; SAVE token

TK_DIR		= TK_SAVE+1	; DIR token

TK_DEF		= TK_DIR+1	; DEF token
TK_POKE		= TK_DEF+1	; POKE token
TK_DOKE		= TK_POKE+1	; DOKE token
TK_CALL		= TK_DOKE+1	; CALL token
TK_DO		= TK_CALL+1	; DO token
TK_LOOP		= TK_DO+1	; LOOP token
TK_PRINT	= TK_LOOP+1	; PRINT token

TK_FRAME	= TK_PRINT+1	; was CONT token, -cm

TK_LIST		= TK_FRAME+1	; LIST token

TK_WINDOW	= TK_LIST+1	; was CLEAR token, now WINDOW -cm

TK_NEW		= TK_WINDOW+1	; NEW token
TK_WIDTH	= TK_NEW+1	; WIDTH token
TK_GET		= TK_WIDTH+1	; GET token
TK_SWAP		= TK_GET+1	; SWAP token
TK_BITSET	= TK_SWAP+1	; BITSET token
TK_BITCLR	= TK_BITSET+1	; BITCLR token

; secondary command tokens, can't start a statement

TK_TAB		= TK_BITCLR+1	; TAB token
TK_TO		= TK_TAB+1	; TO token
TK_FN		= TK_TO+1	; FN token
TK_SPC		= TK_FN+1	; SPC token
TK_THEN		= TK_SPC+1	; THEN token
TK_NOT		= TK_THEN+1	; NOT token
TK_STEP		= TK_NOT+1	; STEP token
TK_UNTIL	= TK_STEP+1	; UNTIL token
TK_WHILE	= TK_UNTIL+1	; WHILE token
TK_OFF		= TK_WHILE+1	; OFF token

; opperator tokens

TK_PLUS		= TK_OFF+1	; + token
TK_MINUS	= TK_PLUS+1	; - token
TK_MUL		= TK_MINUS+1	; * token
TK_DIV		= TK_MUL+1	; / token
TK_POWER	= TK_DIV+1	; ^ token
TK_AND		= TK_POWER+1	; AND token
TK_EOR		= TK_AND+1	; EOR token
TK_OR		= TK_EOR+1	; OR token
TK_RSHIFT	= TK_OR+1	; RSHIFT token
TK_LSHIFT	= TK_RSHIFT+1	; LSHIFT token
TK_GT		= TK_LSHIFT+1	; > token
TK_EQUAL	= TK_GT+1	; = token
TK_LT		= TK_EQUAL+1	; < token

; functions tokens

TK_SGN		= TK_LT+1	; SGN token
TK_INT		= TK_SGN+1	; INT token
TK_ABS		= TK_INT+1	; ABS token
TK_USR		= TK_ABS+1	; USR token
TK_FRE		= TK_USR+1	; FRE token
TK_POS		= TK_FRE+1	; POS token
TK_SQR		= TK_POS+1	; SQR token
TK_RND		= TK_SQR+1	; RND token
TK_LOG		= TK_RND+1	; LOG token
TK_EXP		= TK_LOG+1	; EXP token
TK_COS		= TK_EXP+1	; COS token
TK_SIN		= TK_COS+1	; SIN token
TK_TAN		= TK_SIN+1	; TAN token
TK_ATN		= TK_TAN+1	; ATN token
TK_PEEK		= TK_ATN+1	; PEEK token
TK_DEEK		= TK_PEEK+1	; DEEK token
TK_LABERR	= TK_DEEK+1	; LABERR token -cm, was SADD
TK_LEN		= TK_LABERR+1	; LEN token
TK_STRS		= TK_LEN+1	; STR$ token
TK_VAL		= TK_STRS+1	; VAL token
TK_ASC		= TK_VAL+1	; ASC token
TK_UCASES	= TK_ASC+1	; UCASE$ token
TK_LCASES	= TK_UCASES+1	; LCASE$ token
TK_CHRS		= TK_LCASES+1	; CHR$ token
TK_HEXS		= TK_CHRS+1	; HEX$ token
TK_BINS		= TK_HEXS+1	; BIN$ token
TK_BITTST	= TK_BINS+1	; BITTST token
TK_MAX		= TK_BITTST+1	; MAX token
TK_MIN		= TK_MAX+1	; MIN token
TK_PI		= TK_MIN+1	; PI token
TK_SCANKEY	= TK_PI+1	; was TWOPI token -cm
TK_VPTR		= TK_SCANKEY+1	; VARPTR token
TK_LEFTS	= TK_VPTR+1	; LEFT$ token
TK_RIGHTS	= TK_LEFTS+1	; RIGHT$ token
TK_MIDS		= TK_RIGHTS+1	; MID$ token
TK_POSITION	= TK_MIDS+1	; secondary graphic Tokens -cm
TK_GRID		= TK_POSITION+1
TK_SIZE		= TK_GRID+1
TK_MOVE		= TK_SIZE+1
TK_POINT	= TK_MOVE+1
TK_LINE		= TK_POINT+1	; $F1, Token 113
TK_RECT		= TK_LINE+1
TK_FILL		= TK_RECT+1	; FILL rect
TK_CLEAR	= TK_FILL+1
TK_BORDER	= TK_CLEAR+1
TK_CIRCLE	= TK_BORDER+1	; $F6, Token 118
TK_WAVE		= TK_CIRCLE+1	; $F7, Token 119

; offsets from a base of X or Y

PLUS_0		= $00		; X or Y plus 0
PLUS_1		= $01		; X or Y plus 1
PLUS_2		= $02		; X or Y plus 2
PLUS_3		= $03		; X or Y plus 3

LAB_STAK	= $0100	; stack bottom, no offset

LAB_SKFE	= LAB_STAK+$FE	; flushed stack address
LAB_SKFF	= LAB_STAK+$FF	; flushed stack address

ccflag		= $0200		; BASIC CTRL-C flag, 00 = enabled, 01 = dis
ccbyte		= ccflag+1	; BASIC CTRL-C byte
ccnull		= ccbyte+1	; BASIC CTRL-C byte timeout

VEC_CC		= ccnull+1	; ctrl c check vector


; Ibuffs can now be anywhere in RAM, ensure that the max length is < $80

Ibuffs		= $0220
Ibuffe		= Ibuffs+79	; end of input buffer
