Map to RAM OUT&HFE,3 for to memorize 18 LEVELS SCENE GAME in 2 files BINARY from BASIC for MSX2.

By gasparrini

Champion (298)

gasparrini's picture

18-09-2018, 18:03

Hello Gentilmens Users MSX of the world,

Unfortunately in my big project in question I have little RAM memory
both first two banks of 16K RAM in total are available
only 32K.

That's why, I think it would be better to put all these 18 levels
gameplay as a scenario on MEMORY MAPPER with OUT&HFE,3
and retrieve them using POKE from BASIC from the MSX2 system area.

Here under you find the two routines as an example so
map them with OUT&HFE,3 and then recall them from BASIC
with POKE and DEFUSR=addrr:A=USR(0)

First part

;
; DOOR KEY LEVELS 1-9
;
; Prog: LEVELS VIDEOGAME FOR DOOR KEY
; FIRST PART FROM 1 UNTIL 9 LEVELS
; Code: EDIZIONI DATAPRINT MAGAZINE (C) 2018
; Date: 1/9/2018
;
; **************************************************************
; LAST TIME DATA 15/9/2018 in UPDATE SOURCE ASSEMBLER ZILOG Z80
; FOR MSX2 in MODE SCREEN 4 IN SCREEN 1
; **************************************************************
;
; File name DOORLEV.BIN
;
; Coded in TeddyWareZ' Chaos Assembler 3
;
; (C) 2018 EDIZIONI DATAPRINT MAGAZINE

LDIRVM .equ $005C ; routine del BIOS usata per riempire la VRAM
CHRPUT .equ $1800 ; CHAR PUT (PRINT BASIC)


.org $B000 - 7

.db $fe
.dw startProgram,endProgram,startProgram

startProgram:

jr main

sel:
.db 0 ; SELECT LEVEL OF THE SCENE IN GAMEPLAY

main:
ld ix,table
ld a,(sel)
add a,a
ld c,a
ld b,0
add ix,bc
ld l,(ix+0)
ld h,(ix+1)

ld de,CHRPUT+64
ld bc,32*22
call LDIRVM
RET

table: .DW LEVEL1,LEVEL2,LEVEL3,LEVEL4,LEVEL5
          .DW LEVEL6,LEVEL7,LEVEL8,LEVEL9

LEVEL1:
.........
.........

LEVEL2:
.........
.........

LEVEL3:
.........
.........
LEVEL4:
.........
.........
LEVEL5:
.........
.........

LEVEL6:
.........
.........

LEVEL7:
.........
.........

LEVEL8:
.........
.........

LEVEL9:
.........
.........

endProgram:

.end

Second part

;
; DOOR KEY LEVELS 10-18
;
; Prog: LEVELS VIDEOGAME FOR DOOR KEY
; SECOND PART FROM 10 UNITL 18 LEVELS
; Code: EDIZIONI DATAPRINT MAGAZINE (C) 2018
; Date: 16/9/2018
;
; **************************************************************
; LAST TIME DATA 16/9/2018 in UPDATE SOURCE ASSEMBLER ZILOG Z80
; FOR MSX2 in MODE SCREEN 4 IN SCREEN 1
; **************************************************************
;
; File name DOORLEV2.BIN
;
; Coded in TeddyWareZ' Chaos Assembler 3
;
; (C) 2018 EDIZIONI DATAPRINT MAGAZINE

LDIRVM .equ $005C ; routine del BIOS usata per riempire la VRAM
CHRPUT .equ $1800 ; CHAR PUT (PRINT BASIC)


.org $C900 - 7

.db $fe
.dw startProgram,endProgram,startProgram

startProgram:

jr main

sel:
.db 0 ; SELECT LEVEL OF THE SCENE IN GAMEPLAY

main:
ld ix,table
ld a,(sel)
add a,a
ld c,a
ld b,0
add ix,bc
ld l,(ix+0)
ld h,(ix+1)

ld de,CHRPUT+64
ld bc,32*22
call LDIRVM
RET

table: .DW LEVEL10,LEVEL11,LEVEL12,LEVEL13,LEVEL14
          .DW LEVEL15

LEVEL10:
.........
.........

LEVEL11:
.........
.........

LEVEL12:
.........
.........
LEVEL13:
.........
.........
LEVEL14:
.........
.........

LEVEL15:
.........
.........

endProgram:

.end

Here under there is a example of as must to be the loader for manage memory
mapper in OUT&HFE,3 for to memorize 18 LEVELS SCENE GAME in 2 files BINARY from BASIC for MSX2.

10 IF PEEK(&HF677)=128 THEN POKE &HC000,0:POKE&HF677,&HC0:RUN"RAM16K.BAS"
20 OUT &HFE,2:BLOAD"MUSIC.BIN":OUT &HFE,1:REM start music at 4000h
22 PS=(INP(&HA8)AND192)/64:S=PS+PEEK(&HFCC1+PS)+(PEEK(&HFCC5+PS)AND192)/16:REM calculate slot ID
24 POKE &HFA00,&HF7:POKE &HFA01,S:POKE &HFA02,&H0:POKE &HFA03,&H40:POKE &HFA04,&HC9:DEFUSR0=&HFA00 : REM Poke insterslot call to START
26 POKE &HFA05,&HF7:POKE &HFA06,S:POKE &HFA07,&H20:POKE &HFA08,&H40:POKE &HFA09,&HC9:DEFUSR1=&HFA05 : REM Poke insterslot call to INTON
28 POKE &HFA0A,&HF7:POKE &HFA0B,S:POKE &HFA0C,&H50:POKE &HFA0D,&H40:POKE &HFA0E,&HC9:DEFUSR2=&HFA0A : REM Poke insterslot call to INTOFF
29 U=USR(0):U=USR1(0): REM start and play
30 REM poke &Hf677,128:RUN"GAMEBOOT.BAS"

I really hope that some of you are kind and able
to solve my problem of software development.

For the moment it's all, thanks in advance
Best Regards and Happy MSX
(^_^)
Andrea Gasparrini from Italy

Login or register to post comments

By Manuel

Ascended (14782)

Manuel's picture

18-09-2018, 18:19

What is the problem? You didn't actually state what the problem is.

By gasparrini

Champion (298)

gasparrini's picture

18-09-2018, 22:07

Hello Manuel and to all you gentilments users MSX,

I ask sorry to all of you if you do not do that in any way
I'm well explained.

So, the point of the situation is as follows:

I would like to allocate my two routines in assembler, once compiled
in binary files, which contain all 18 levels of play via ASCII code,
in SCREEN1, but in my case of my project in question we used
the SCREEN4 IN SCREEN 1 mode, doing a trick with the VDP registers.

Therefore, I would like to allocate these two binary files on the memory mapper for MSX2,
and from BASIC using with OUT&HFE,3

Because already on OUT&HFE,2 music is already stored in binary with the PSG.

I hope I have explained myself well this time, I understand that at the level of programming is a very
difficult thing to solve, that's why I'm here with you to kindly ask your help forever.

See you to soon as always......

By PingPong

Prophet (3147)

PingPong's picture

19-09-2018, 01:02

the sodomizer of the English language

By Manel46

Champion (324)

Manel46's picture

19-09-2018, 10:17

Friend respect!

By gdx

Prophet (2352)

gdx's picture

19-09-2018, 10:34

If you put data on 8000h~BFFFh to read them with POKE or USR, you must reduce the BASIC program. It must start at C000h. Use the memory map for this.

https://www.msx.org/wiki/The_Memory

By Manel46

Champion (324)

Manel46's picture

19-09-2018, 13:50

Friend gasparrini.
I also use a translator. It's a problem.
Look at the pdf "Top Secret", from the Brazilian colleagues, you can understand well the being in portuges, a Latin language. Check it out on Google. Animos, that with illusion can achieve many things in programming.

By Kai Magazine

Paragon (1238)

Kai Magazine's picture

19-09-2018, 14:04

gasparrini wrote:

Hello Manuel and to all you gentilments users MSX,

I ask sorry to all of you if you do not do that in any way
I'm well explained.

So, the point of the situation is as follows:

I would like to allocate my two routines in assembler, once compiled
in binary files, which contain all 18 levels of play via ASCII code,
in SCREEN1, but in my case of my project in question we used
the SCREEN4 IN SCREEN 1 mode, doing a trick with the VDP registers.

Therefore, I would like to allocate these two binary files on the memory mapper for MSX2,
and from BASIC using with OUT&HFE,3

Because already on OUT&HFE,2 music is already stored in binary with the PSG.

I hope I have explained myself well this time, I understand that at the level of programming is a very
difficult thing to solve, that's why I'm here with you to kindly ask your help forever.

See you to soon as always......

If the game is for msx2, and screen 4, use the extra vram to store the maps in bytes as a bitmap (.sc5 or whatever) and read the bytes with vpeek or with inp() if you requiere more speed.

By RetroTechie

Paragon (1461)

RetroTechie's picture

19-09-2018, 15:01

gasparrini wrote:

I hope I have explained myself well this time (..)

Sorry to say you haven't, and it is NOT a language problem imho. More in the area of documentation / problem analysis as done by yourself. As in: it isn't clear to yourself what the problem is (or what you want to do exactly), and that makes it difficult to explain to others. Posting a chunk of code doesn't help much if it isn't clear what it's supposed to do, context, data structure, or which parts work / which parts don't.

Quote:

I understand that at the level of programming is a very difficult thing to solve

Actually this is a fairly simple one. I went over the code yesterday evening, and several things became obvious. Problem is those things only became obvious from looking at the code, NOT because you told us. That also makes it harder for us to understand the issue, and thus less likely someone will help. Again: not a language issue (although the language issue doesn't help either). Some observations:

  • Data for each level is a fixed size block of 32*22 = 704 bytes that's copied from RAM -> VRAM. For 18 levels that's 18*704 = 12672 bytes, which easily fits in a single mapper block -> no need to split up level data in 2 separate .bin files. Because level data is fixed size, start of each block can be calculated, that is: no need for a list of dw's with address of each level.
  • Afaict there's no need to do any slot switching. BASIC part does some calculation of a slot ID, which on a disk-BASIC MSX can simply be taken from a system variable. Then several interslot-call routines are installed, which aren't needed because with the data/code in 8000-BFFFh, code can be CALLed directly. If memory switching in 8000-BFFFh is needed because a BASIC program is running there, machine code can simply switch mapper blocks & leave slot settings alone.
  • When doing a USR(X) function call, parameters can be passed from, and back to BASIC in the BASIC statement itself. Seen from the assembler code, 2 system variables are used for that: VALTYP (F663h) and DAC (F7F6h). Assuming BASIC takes care an integer (level #) is passed, VALTYP can be ignored, and integer passed is found at DAC+2.

A simple setup would be to put the level data in a single mapper block, starting with the data first, followed by the code, so that everything starts at fixed addresses. The single .bin file might look something like this:


LDIRVM  .equ $005C ; copy data from RAM -> VRAM
CHRPUT  .equ $1800 ; destination address in VRAM
DAC     .equ $F7F6 ; buffer for argument passed from / to BASIC


    .db $fe
    .dw startProgram,endProgram-1,runAddress

    .org $8000

startProgram:

level_data:
  (level 1 data)   ; 32*22 = 704 bytes
  (level 2 data)
    .
    .
  (level 18 data)  ; total 18 * 704 = 12672 bytes

main:
    ld a,(DAC+2)   ; level (1-18) passed from BASIC
    ld hl,level_data-704
    ld bc,32*22
add704:
    add hl,bc
    dec a
    jr nz,add704

    ld de,CHRPUT+64
    call LDIRVM

runAddress:        ; just in case this .bin is BLOAD,R-ed by accident
    ret

endProgram:
    .end

If as gdx suggested, main BASIC program starts at C000h, "main" can be called directly with a USR(X) statement.

If BASIC needs more space and starts at 8000h, you could use a small helper routine that does the equivalent of:

    ld a,3
    out (FEh),a
    call main
    ld a,1
    out (FEh),a
    ret

Similar thing for calling the music code from a '32K sized' BASIC program.

My MSX profile