ASM first steps.

Página 1/2
| 2

Por FiXato

Scribe (1742)

Imagen del FiXato

12-03-2010, 02:02

Okay, I know I will most likely sound like a n00b instead of a newb (yes, there is a difference) by making this post since all the information must be online already, but I've honestly tried using resources out there (MAP, The Redbook, looking at examples' code (which most of the time was getting too complex/did too much at the same time), googling, looking at older dev threads here, etc), but it hasn't really helped me much. It's either too complex, written too technically, or assumes you know where to find exactly what you are looking for.

So, I was wondering if the people here can guide me by the hand and perhaps spoonfeed me a bit. Kinda imagine you have to teach your kid how to cycle.

What am I not looking for?
- "OMG N00b! Can't you do anything alone?!?!111"
- "RTFM"
- Just read these and these books from cover to cover
and more of those kind of responses.
If you can't contribute in an expressive step by step way, I'd appreciate it if you would refrain from responding. :) I like to stay motivated you know. :D
It might sound a bit harsh and perhaps redundant, but negative remarks can really demotivate me and put me off this thing completely.
I'm also not really looking for the most optimised solutions either.

So, now that we've got that out of the way:

What am I looking for?
I'd like to get started with creating simple ROMs for the MSX that do simple or funny (graphical) stuff.
The best way for me to learn new things, especially in programming, is to have simple tutorials that explain every step and only do 1 thing at a time.

Any progress I make will be tracked at my Git repository

I don't feel the need to necessarily restrict myself to just the MSX. MSX2 is good for me as well. I just want to learn the simplest way of doing things. However, since it is mostly ASM that I want to learn, I'd like to stick with that, and not BASIC.

So, let's start with the first 'lesson' I'd like to learn:
1. Create a simple graphic.
2. Load this graphic into memory.
3. Show a single tile from this graphic on screen.
4. Move the tile/graphic around.

Step 1 should be simple. I guess with any MSX graphics program you can create one.
With Vampier's GraphicCoder I made the following simple start for a tileset: cars.sc5
msx.fixato.net/cars-sc5.png

Now, who can show me the way to steps 2, 3 and 4?

Login sesión o register para postear comentarios

Por Vampier

Prophet (2413)

Imagen del Vampier

12-03-2010, 04:40

well read from memory:
- input the file into vram (a non visible page)

- then find out the x,d and (xd==x+16 && yd=y+16) coords. Read line by line since I don't think a block is do-able in one operation the translation of the target coords should be done on the fly.

step 3 and 4 are one step imho

Por SLotman

Paragon (1242)

Imagen del SLotman

12-03-2010, 04:52

Since you're doing a ROM, first I would recommend ASMSX. Very nice, and it really makes ROM development easier Smile

After you draw your graphic, you must first convert it to MSX. For this you can use MSXViewer, BMP2MSX or any other tool around - even the one I made and put inside MSXPad Wink

For screen5 you should also convert the pallete.

Then it's just a matter of including the data on the ROM (just include it for a simple test, later you should compress it, since it could take a lot of space) - on ASMSX just a matter of writing ".incbin <filename>" Smile

Then it's just a matter of transfer ROM->VRAM contents. with something like this:

;; WRITE_TO_VRAM
;; transfer data from RAM (or ROM) to VRAM
;
; Parameters:
; BC = Bytes to transfer
; HL = Source address on RAM
; DE = Destination address on VRAM
;WRITE_TO_VRAM:
                                DI
setvdpwt:
                                LD      A,(MSXType)     ; MSX version
                                CP      0                      ; is it MSX1?
                                JR      Z,wtvram1        ;
                                XOR     A
                                OUT     (099h),A
                                LD      A,08Eh
                                OUT     (099h),A

wtvram1:
                                LD      A,E
                                OUT     (099h),A
                                LD      A,D
                                AND     03Fh
                                OR      040h
                                OUT     (099h),A

ldirvram:
                                LD      A,(HL)
                                OUT     (098h),A
                                INC     HL
                                DEC     BC
	                        INC	DE
                                LD      A,B
                                OR      C
                                CP      0
                                JP      NZ, ldirvram

                                LD      A,(HL)
                                OUT     (098h),A

                                EI
                                RET

First check if it's MSX1 or MSX2. On MSX2 (or higher) you must set VDP for write first. Then you do two OUTs to select where on VRAM you'll start writing, and after that, it's just a matter of spilling bytes with OUT 98h,A Wink

After that you should have your image on your screen. To show just one tile, look at MAP on VDP commands (so you can copy block graphics from one area to another, just like the MSX2 BASIC 'COPY' command.

Por ARTRAG

Enlighted (6935)

Imagen del ARTRAG

12-03-2010, 08:04

Fixato you start from the wrong part
I suggest you start understanding how to do a rom (If that is what you want, a com or bin file are simpler) and what vdp you want to use

If you want a rom, the 16K rom is the simplest way and you can assume that the code and ata starts at 0x4000
to have more than 16K you have to fight with slots
on the opposite, with a com file you can use about 55K of ram/rom, but you cannot use the Bios

about the vdp, I would study the one vdp mode of you choice
but for testing I would start from a text mode and from a simple
"hello world" program

PS
just an option: do you program in C?
It is a good idea start using C and asm: It can handle easily large projects
if you go for a .com file
the HTC compiler is the best solution

Por ro

Scribe (4963)

Imagen del ro

12-03-2010, 08:35

total noob, dude! Tongue

Por bore

Master (166)

Imagen del bore

12-03-2010, 09:12

Also, if you don't already know C I think it is a good idea to stay away from it until you find that you have no problem writing fairly complex programs in assembler.
It seems quite common that people who only program C have a big problem with stuff like pointers, jumptables and similiar.

As Artrag pointed out, start small, try to modify the characters on screen in the first textmode. To be able to do this you will have to find out how the characters are mapped to the video memory.

You might also learn to hate the VDP-manual. (MSX probably has the worst documentation of all computers ever.)
Yes, I know didn't ask for that but have a look at the VDP-manual anyway, you will not have to understand how all registers work, but if you just brush through the manual you will get an idea of what to ask for.

If you have any trouble getting output at all, try changing the palette instead. Changing the background color is an exellent debug method that can be used to track down nasty crash-bugs. (By changing background in different parts of your program you will end up with a different color depending on where the program crashed.)

Por Huey

Prophet (2694)

Imagen del Huey

12-03-2010, 09:53

Initialisation of the screen mode was my biggest problem until now. The VDP manual did not help me at all. Evil

The steps you are taking are BIG steps for a beginning programmer. But not impossible at all. Just don't give up. ASM is easier (and more fun) than it looks.

I myself started (a couple of weeks ago) using Sjasm + a ready to be found 48K ROM stub + the book "Z-80 Assembly Language Programming (1979)(Leventhal)".
After some days I started to understand reading ASM code. Especially the F register flags was a bit confusing at start. But later on it became a thankfull mechanism.

Por Creepy

Champion (335)

Imagen del Creepy

12-03-2010, 11:14

I started a few weeks ago too. Got sjasm which has some stubs for COM, BIN or ROM files and started coding. I started reading Programming the Z-80 3rd Edition (Rodnay Zaks) for understanding the Z80 and got some docs for MSX 1 and 2 to start to understand the hardware. Then I just started programming some stuff.

The first thing I tried after using a sjasm COM stub was to write a keypressed routine in ASM which I posted in this forum (=http://www.msx.org/forumtopic10818p45.html). The next step for me was to initialize screen 2 and to show stuff on the screen. Then I used that to make a fake scrolling effect. If you want I can post the code with comments.

Por MOA

Champion (293)

Imagen del MOA

12-03-2010, 12:40


<snip>

                                LD      A,B
                                OR      C
                                CP      0
                                JP      NZ, ldirvram

<snip>

That CP 0 is a bit redundant as OR C already sets the flags.

(Never mind, the topic starter wasn't interested in optimal code, but couldn't resist.)

Your routine also writes an extra byte to VRAM (the final LD A,(HL) / OUT (0x98),A)), i.e. if BC == 1, the routine will write 2 bytes instead of 1.

For a beginner I would advice to use BIOS calls for most low-level stuff, it'll help you to get results much faster.

LDIRMV

Address : #0059
Function : Block transfer to memory from VRAM
Input : BC - blocklength
DE - Start address of memory
HL - Start address of VRAM
Registers: All

(http://map.grauw.nl/resources/msxbios.php)

Por muffie

Paladin (933)

Imagen del muffie

12-03-2010, 15:24

Open notepad and type

org #4000
db "AB"
dw start
db 00,00,00,00,05,00

start:
;; put your code here
     

save it as fixato.mac and...

c:> pasmo fixato.mac fixato.rom

Load it in your favorite MSX emulator

Por RetroTechie

Paragon (1563)

Imagen del RetroTechie

12-03-2010, 17:36

I'm gonna repeat a suggestion I made earlier in this thread. Not because I'd want you to start using a ZX Spectrum (emulator), but because "The Complete Machine Code Tutor" is the most easy, interactive / 'fun' way to learn Z80 assembly that I know of.

I wish there'd be something equivalent on the MSX, but sadly, there isn't. Not even close *_* (AFAIK, please correct me if you know a good interactive Z80-assembly-teaching thingie for MSX). Also the MSX is quite a bit more complicated in terms of hardware and built-in system software.

Página 1/2
| 2