Stumped (entry level ASM, gah)

Page 4/6
1 | 2 | 3 | | 5 | 6

By Driehoogvoor

Resident (52)

Driehoogvoor's picture

13-08-2014, 15:53

MSX_Noob: I have no idea why that would happen, sorry. Sad

AxelF: Thanks! Smile I don't have SJASM, but I'll download it tonight and try it out to see if I can replicate the screen 0 problem. I haven't built the star field to a file yet, only ran it straight from Compass.

By MSX_Noob

Resident (51)

MSX_Noob's picture

13-08-2014, 17:28

Donated!

Me neither, D.H.V., but I'll start with the basics first.
(ps: I used both Sjasm and Glass, same output)

By Driehoogvoor

Resident (52)

Driehoogvoor's picture

15-08-2014, 09:50

AxelF: I haven't been able to get SJASM to work (I probably didn't try hard enough), but I did find what causes the black screen after quitting the program. I'm setting the palette in screen 5, but I don't restore it when switching back to screen 0. Replacing the CHDMOD call with SETTXT (like you said) indeed fixes this. Thanks! Smile

By AxelF

Champion (395)

AxelF's picture

15-08-2014, 22:02

You can read the Sjasm manual online.
Notice the Output; paging and code parts chapter, its a bit tricky.

Below you see the Starfield code ready for Sjasm compiling.
It is more save to run the code from #9000 or #C000 in stead of #4000
if you compile a .BIN file to be run from BASIC.. ( The Basic ROM is located in #4000 to #7FFF when in Basic )

	output Stars.bin

	defpage 0
	defpage 1,#C000

	page 0
	code
	byte #FE
	word #c000
	word #c000+(::1)-1
	word start

	page 1
	code
	
start:	

               ORG #c000

NEWKEY         EQU #FBE5


               ; ---------------- M A I N ----------------


               ; Initialize the program.

               CALL SET_SCREEN5      ; Set the graphic mode.

               LD HL,PALETTE         ; Set the palette.
               CALL SET_PALETTE

               LD HL,LOOP            ; Start the main loop.
               CALL SET_HTIMI


               ; Wait for the space bar.

SPACE          LD A,(NEWKEY+8)       ; Wait for the space bar.
               BIT 0,A
               JP NZ,SPACE


               ; End the program.

               LD HL,HTIMI           ; Stop the main loop.
               CALL RES_HTIMI

               CALL SET_SCREEN0      ; Switch back to text mode.

               RET


               ; ---------------- L O O P ----------------


               ; Update all stars.

LOOP           LD A,(READY)          ; Do nothing if not ready.
               CP A,0
               JP Z,HTIMI

               XOR A                 ; Mark the loop as not ready.
               LD (READY),A

               DI

               LD IX,STARS
               LD B,36

UPDATE         PUSH BC

               CALL UPDATE_STAR      ; Update the current star.

               INC IX                ; Fetch the next star.
               INC IX
               INC IX

               POP BC
               DJNZ UPDATE

               EI

               LD A,1                ; Mark the loop as ready.
               LD (READY),A

HTIMI          DB 0,0,0,0,0          ; Call the original H.TIMI.


               ; ----------- F U N C T I O N S -----------


               ; Update a star.
               ;
               ; - IX : The star data

UPDATE_STAR    CALL GET_POSITION     ; Delete the star from VRAM.
               CALL WRITE_VRAM

               XOR A
               OUT (#98),A

               LD A,(IX)             ; Update the star's x-position.
               LD B,(IX+2)
               SLA B                 ; Faster, faster! /o/
               SUB A,B
               LD (IX),A

               CALL GET_POSITION     ; Write the star to VRAM.
               CALL WRITE_VRAM

               LD A,(IX+2)
               OUT (#98),A

               RET


               ; Get a star's VRAM position.
               ;
               ; - IX : The star data

GET_POSITION   LD A,(IX)             ; Fetch the x-position.
               LD E,A

               LD A,(IX+1)           ; Fetch the y-position.
               LD D,A

               SRL D                 ; Shift the y-position right because
               XOR A                 ; there are two pixels per byte.
               RRA

               SRL E                 ; Do the same for the x-position,
               AND E                 ; adding the carry from the y-shift.

               XOR A                 ; Store the address in AHL.
               EX DE,HL

               RET


               ; --------------- H O O K S ---------------


               ; Set the H.TIMI hook.
               ;
               ; - HL : The routine

SET_HTIMI      PUSH HL

               DI

               LD HL,#FD9F
               LD DE,HTIMI
               LD BC,5
               LDIR

               LD A,#C3
               LD (#FD9F),A
               POP HL
               LD (#FDA0),HL

               EI
               RET


               ; Restore the H.TIMI hook.
               ;
               ; - HL : The H.TIMI backup

RES_HTIMI      DI

               LD DE,#FD9F
               LD BC,5
               LDIR

               EI
               RET


               ; --------------- V I D E O ---------------


               ; Switch to screen 0.
SET_SCREEN0
		   CALL #78
		   RET


               ; Switch to screen 5.

SET_SCREEN5    LD A,5
               CALL #005F

               RET


               ; Set the palette data.
               ;
               ; - HL : The palette data

SET_PALETTE    DI

               XOR A
               OUT (#99),A
               LD A,#90
               OUT (#99),A
               LD BC,#209A
               OTIR

               EI
               RET


               ; Ready the VRAM for writing.
               ;
               ; - AHL : The VRAM address

WRITE_VRAM     RLC H
               RLA
               RLC H
               RLA
               SRL H
               SRL H

               OUT (#99),A
               LD A,#8E
               OUT (#99),A
               LD A,L
               OUT (#99),A
               LD A,H
               OR 64
               OUT (#99),A

               RET


               ; --------------- F L A G S ---------------


READY          DB 1


               ; ---------------- D A T A ----------------


               ; Palette data.

PALETTE        DW #0000
               DW #0333
               DW #0444
               DW #0777

               DW #0000
               DW #0000
               DW #0000
               DW #0000

               DW #0000
               DW #0000
               DW #0000
               DW #0000

               DW #0000
               DW #0000
               DW #0000
               DW #0000


               ; Star data.
               ;
               ; - x-coordinate
               ; - y-coordinate
               ; - type (speed and color)

STARS          DB 144, 0, 3
               DB 141, 6, 1
               DB 146, 12, 3
               DB 5, 18, 2
               DB 243, 24, 1
               DB 60, 30, 2
               DB 29, 36, 2
               DB 44, 42, 1
               DB 143, 48, 2
               DB 122, 54, 1
               DB 137, 60, 1
               DB 201, 66, 1
               DB 186, 72, 3
               DB 30, 78, 3
               DB 189, 84, 2
               DB 38, 90, 2
               DB 238, 96, 3
               DB 38, 102, 1
               DB 204, 108, 1
               DB 188, 114, 1
               DB 140, 120, 3
               DB 105, 126, 3
               DB 17, 132, 2
               DB 240, 138, 2
               DB 108, 144, 2
               DB 227, 150, 2
               DB 113, 156, 1
               DB 74, 162, 1
               DB 44, 168, 2
               DB 153, 174, 2
               DB 111, 180, 2
               DB 3, 186, 2
               DB 253, 192, 1
               DB 79, 198, 3
               DB 254, 204, 1
               DB 191, 210, 3
			   
end

By Driehoogvoor

Resident (52)

Driehoogvoor's picture

15-08-2014, 23:23

Thanks, I understand how it works now. I'm coding in Compass, and this morning I was trying to make a BIN file that I could run from Basic. Needless to say, I ran into that #4000 address problem, haha. I now start my code from #8000, as the BIOS and BASIC roms are in slots 0 and 1, and that works perfectly. In Compass, you have to specify the start and end addresses of the memory block where the program will be loaded, and the address to start execution—the BIN header, basically.

The SJASM wrapper looks like it does exactly the same, except for address #C000. You already changed the SET_SCREEN0 function, so I'm guessing it works just fine now? I'll try compiling it with SJASM myself later. Smile

By MSX_Noob

Resident (51)

MSX_Noob's picture

19-08-2014, 16:49

Can I compete in noob-ness again? Smile

I'm reading and trying to understand this page:
http://map.grauw.nl/articles/vdp_tut.php

I would not dare to say the content is "wrong" but when I copied the code for the VDP example
I had to make some changes to get it running.

Especially this part: (Wbass uses &H for hex)

	xor	a		;set vram write base address
	ld	hl,&H8000	; to 1st byte of page 1...
	call	SetVDP_Write

With this nothing to appear on the screen.

When I changed to HL,&H00 (patern name table?) it worked.

I'm trying to understand why...

ps: I used a basic "LD A,5 - Call &H5F" to get to screen 5.

By Driehoogvoor

Resident (52)

Driehoogvoor's picture

19-08-2014, 17:05

Screen 5 has 4 pages, of which one is displayed on the screen. If you haven't switched pages, you're looking at page 0. The VRAM address for page 0 starts at &H0000. The code you're using to set up the VDP for writing, sets the address at &H8000. That's the start of page 1, so that pixel would be invisible for you.

By AxelF

Champion (395)

AxelF's picture

19-08-2014, 17:29

Yes, WBass2 uses &H for hex values, but you can change this with the SET/H v/a,"string" command
so if you want to change it to for example # use...

SET/H V,"#"

The complete DUTCH WBass2 manual is available online

By Grauw

Ascended (10577)

Grauw's picture

19-08-2014, 17:29

In that DoExampleCopy example routine, it writes 8 lines of red pixels to page 1 using VRAM access, then copies an 8x8 square of those red pixels to page 0 with a VDP command.

If you just try the first half of the example, nothing will be visible, but as a whole it should work…

By MSX_Noob

Resident (51)

MSX_Noob's picture

19-08-2014, 18:10

Thanks everyone, I will revise my code and see where it went wrong...

Page 4/6
1 | 2 | 3 | | 5 | 6