Karoshi MSX Community
21 de Agosto de 2019, 03:44:27 am *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: MSX-BASIC expansion in page 1  (Leído 5254 veces)
0 Usuarios y 1 Visitante están viendo este tema.
jltursan
Karoshi Forum's Guru
*******
Mensajes: 1516


¿Que es lo que has aprendido hoy?


WWW Email
« : 12 de Mayo de 2007, 01:37:02 pm »

Here's a routine to expand MSX-BASIC with new commands. It uses the ROM cartridge method to add new commands via CALL statement.

Código:
.BIOS
.PAGE 1

CSRY equ $F3DC
MNROM equ $FCC1
PROCNM equ $FD89

; standar ROM header with STATEMENT call defined
DEFB $41,$42
DEFW 0
DEFW STATEMENT
DEFW 0
DEFW 0
DEFS 6

STATEMENT: push hl ; preserves current pointer to command text buffer
ld ix,CMDTAB
ld bc,4
@@STLOOP: ld l,[ix+0] ; loads in HL the string address of the keyword to be compared with PROCNM buffer
ld a,[ix+1]
or a
jp z,SYNTAXERR ; if zero, we've reached end of list, so keyword hasn't been recognized = SYNTAX ERROR
ld h,a
ld de,PROCNM
call MEMCMP ; both strings are compared
jr nz,@@NOMATCH
pop hl ; they are equal, so
ld e,[ix+2]
ld d,[ix+3]
push de
pop ix ; we must load in IX the address of the new command implementation and
jp [ix] ; jump into...
@@NOMATCH: add ix,bc ; no match, we need to compare with the next keyword stored in table
jr @@STLOOP
SYNTAXERR: pop hl ; generate a SYNTAX ERROR
xor a
ccf  ; carry flag=1
ret
MEMCMP: ld a,[de] ; compare two strings in HL & DE
cp [hl]
ret nz
or a
inc hl
inc de
jr nz,MEMCMP
ret

;
; Command/keywords implementation starts here
; DE=text address next to the expansion statement name
;

; Command 1: fills screen (mode 0) with a specified character
CMD1CODE:
push hl  ; IMPORTANT!! we must to preserve HL
ld a,[hl]
cp $28 ; looks for (
jp nz,SYNTAXERR
inc hl
ld a,[hl]
cp $22 ; looks for "
jp nz,SYNTAXERR
inc hl
ld b,[hl] ; load parameter
inc hl
ld a,[hl]
cp $22 ; looks for "
jp nz,SYNTAXERR
inc hl
ld a,[hl]
cp $29 ; looks for )
jp nz,SYNTAXERR
LOOP3: inc hl
ld a,[hl]
cp $20 ; eat blanks
jr z,LOOP3
or a ; ends with zero?
jr z,DOCMD1
cp $3A ; ends with :?
jp nz,SYNTAXERR
DOCMD1:
push hl
ld hl,0
ld a,b
ld bc,$800
call FILVRM
pop hl
pop bc
xor a  ; carry flag=0
ret

; Command 2 : prints version!
CMD2CODE:
push hl ; IMPORTANT!!, we must to keep HL
ld a,[CSRY]
ld l,a
ld h,1
call POSIT
ld hl,MSG
@@PRNTLOOP: ld a,[hl]
or a
jr z,@@PRNTEND
call CHPUT
inc hl
jr @@PRNTLOOP
@@PRNTEND: pop hl
ret

MSG: DT "EXTENDED BASIC v0.1",0

; Command Table : Address of the keyword literal, Address of the command implementation
CMDTAB: DEFW CMD1,CMD1CODE
DEFW CMD2,CMD2CODE
DEFW 0 ; table ends with 0
CMD1: DT "FILLSCREEN",0
CMD2: DT "VERSION",0

DUMMY1: DEFS 7989
DUMMY2: DEFB 0

How to use :

1) Copy+paste
2) Compile and rename the resulting file as a .ROM
3) Load the file & execute it. The BASIC expansion will be installed

New commands added as example (both useless Tongue ):

- CALL VERSION ( or _VERSION )
Prints the version Tongue Tongue

- CALL FILLSCREEN("character") ( or _FILLSCREEN )
Fills screen 0 name table with "character".

NOTE: I've not tested yet in a real MSX. I'm not sure right now about step 3; it could differs between emulators and the real thing.
« Última modificación: 12 de Mayo de 2007, 03:26:44 pm por jltursan » En línea

Doom dee doom dee doom
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!