Learn Multi platform 65816 Assembly Programming... For Monsters!

Hello World Series


Lesson H1 - Hello World on the Super Nintendo
This Example will show a 'Hello World' Message on the SNES.
We'll use WLADX as our assembler

HelloWorld.asm



Showing A 'Hello World' Message

WLADX needs us to define the layout of our memory. We're defining a simple single block of memory $20000 in size. 
We define some direct page entries for our work.

Z_HL is made up of 3 bytes U, H and L for 24 bit addresses.

We also have a CursorX/Y for the next character position.
Our cartridge starts at address $8000.

We begin by stopping interrupts, enabling 65816 mode, and setting the X/Y registers to 16 bit.

The Accumulator and memory functions are still 8 bit.
We need to set up our screen!

Unfortunately there's a lot of strange settings we need to set to do this, but we've got basic values here to set up a screen with a 32x32 tilemap.
We need to set up the colors for our screen. The background is color 0, the font is color 3.
We need to set up a font. We've defined bytes for a 1 bit per pixel font in the code.
We need to transfer our font into pattern RAM.

We load the address of our font into the direct page address z_HL, and copy the bytes into pattern RAM.

Each line of pattern RAM takes 4 bytes.

We send the first two in one block (Bitplanes 0/1), and the matching second two in the second block (Bitplanes 2/3).

We send one line of our font data twice in the first block, and zero bytes in the second block.

This has the effect of setting our font as color 3.
We need to set the scroll position of the tilemap, and zero all the tiles in the tilemap.

The tilemap is 32x32, so there are $400 entries, and each one takes 2 bytes.

Now all our data has been transferred, we can turn on our screen.

Our test program loads the address of the 'Hello World' string into the Z_HL zero page entry, and calls the 'PrintString' subroutine.

It then stops the processor with an infinite loop.
The 'PrintString' routine simply reads one byte at a time from the z_HL direct page.

When we get to the 255 byte we return, otherwise we pass the character to the 'PrintString' routine.
The PrintChar routine will print the character to the screen using the tilemap.
First we need to convert ASCII to the pattern number.

We start by converting lowercase to uppercase, as we have no lowercase in our font.
Next we subtract 64, as our first character is 'A', This converts to the correct tile pattern number.
We now need to calculate the VRAM address.

The tilemap is at VRAM address $0000 onwards, and each line is 32 tiles, so the formula is 'VRAM = (Ypos*32) + Xpos'.

We calculate the destination address with bitshifts.
We now need to wait for VBLANK, as we cannot write to VRAM outside of VBLANK.
Next we select the VRAM address, write the two bytes to select the tile pattern of the character we want to show

(The top byte is zero, the bottom is the pattern number).

We then increase our CursorX position, and return.
At the end of our cartridge we need to define a reset vector, which points to the start of our cartridge.
Getting Hello World to the screen isn't much, but it's a vital step! Once we can get a program running, we can develop it into something much better.

In our Bitmap Series, we went directly to the graphics hardware and used our own font, but We've used the firmware in this example for speed.


Running our Program

To build our ROM, there are two stages, an Assembly stage, and a Linking stage.
Here is a minimal example of a script to assemble an ASM file into a SNES program:

wla-65816.exe -i -D BuildSNS -o \BldSNS\cart.o \sources\Book\HelloWorld.asm
wlalink -i -b \BldSNS\cart.txt \RelSNS\cart.sfc

We need to specify a ASM file to build .We build an intermediary object file. We also define a symbol
We want a Binary file, we specify the destination name
We can start our cartridge from the Load Game option in Snes9x!
We can use the command line to start the disk image with BeebEm
Here is our example running!


 

View Options
Default Dark
Simple (Hide this menu)
Print Mode (white background)

Top Menu
***Main Menu***
Youtube channel
Patreon
Introduction to Assembly (Basics for absolute beginners)
Amazon Affiliate Link
AkuSprite Editor
ChibiTracker
Dec/Bin/Hex/Oct/Ascii Table

Alt Tech
Archive.org
Bitchute
Odysee
Rumble
DailyMotion
Please note: I wlll upload more content to these alt platforms based on the views they bring in

Z80 Content
***Z80 Tutorial List***
Learn Z80 Assembly (2021)
Learn Z80 Assembly (old)
Hello World
Simple Samples
Advanced Series
Multiplatform Series
Platform Specific Series
ChibiAkumas Series
Grime Z80
Z80 Downloads
Z80 Cheatsheet
Sources.7z
DevTools kit
Z80 Platforms
Amstrad CPC
Elan Enterprise
Gameboy & Gameboy Color
Master System & GameGear
MSX & MSX2
Sam Coupe
TI-83
ZX Spectrum
Spectrum NEXT
Camputers Lynx

6502 Content
***6502 Tutorial List***
Learn 6502 Assembly
Advanced Series
Platform Specific Series
Hello World Series
Simple Samples
Grime 6502
6502 Downloads
6502 Cheatsheet
Sources.7z
DevTools kit
6502 Platforms
Apple IIe
Atari 800 and 5200
Atari Lynx
BBC Micro
Commodore 64
Commodore PET
Commander x16
Super Nintendo (SNES)
Nintendo NES / Famicom
PC Engine (Turbografx-16)
Vic 20

68000 Content
***68000 Tutorial List***
Learn 68000 Assembly
Hello World Series
Platform Specific Series
Simple Samples
Grime 68000
68000 Downloads
68000 Cheatsheet
Sources.7z
DevTools kit
68000 Platforms
Amiga 500
Atari ST
Neo Geo
Sega Genesis / Mega Drive
Sinclair QL
X68000 (Sharp x68k)

8086 Content
Learn 8086 Assembly
Platform Specific Series
Hello World Series
Simple Samples
8086 Downloads
8086 Cheatsheet
Sources.7z
DevTools kit
8086 Platforms
Wonderswan
MsDos

ARM Content
Learn ARM Assembly
Learn ARM Thumb Assembly
Platform Specific Series
Hello World
Simple Samples
ARM Downloads
ARM Cheatsheet
Sources.7z
DevTools kit
ARM Platforms
Gameboy Advance
Nintendo DS
Risc Os

Risc-V Content
Learn Risc-V Assembly
Risc-V Downloads
Risc-V Cheatsheet
Sources.7z
DevTools kit

MIPS Content
Learn Risc-V Assembly
Platform Specific Series
Hello World
Simple Samples
MIPS Downloads
MIPS Cheatsheet
Sources.7z
DevTools kit
MIPS Platforms
Playstation
N64

PDP-11 Content
Learn PDP-11 Assembly
Platform Specific Series
Simple Samples
PDP-11 Downloads
PDP-11 Cheatsheet
Sources.7z
DevTools kit
PDP-11 Platforms
PDP-11
UKNC

TMS9900 Content
Learn TMS9900 Assembly
Platform Specific Series
Hello World
TMS9900 Downloads
TMS9900 Cheatsheet
Sources.7z
DevTools kit
TMS9900 Platforms
Ti 99

6809 Content
Learn 6809 Assembly
Learn 6309 Assembly
Platform Specific Series
Hello World Series
Simple Samples
6809 Downloads
6809/6309 Cheatsheet
Sources.7z
DevTools kit
6809 Platforms
Dragon 32/Tandy Coco
Fujitsu FM7
TRS-80 Coco 3
Vectrex

65816 Content
Learn 65816 Assembly
Hello World
Simple Samples
65816 Downloads
65816 Cheatsheet
Sources.7z
DevTools kit
65816 Platforms
SNES

eZ80 Content
Learn eZ80 Assembly
Platform Specific Series
eZ80 Downloads
eZ80 Cheatsheet
Sources.7z
DevTools kit
eZ80 Platforms
Ti84 PCE

IBM370 Content
Learn IBM370 Assembly
Simple Samples
IBM370 Downloads
IBM370 Cheatsheet
Sources.7z
DevTools kit

Super-H Content
Learn SH2 Assembly
Hello World Series
Simple Samples
SH2 Downloads
SH2 Cheatsheet
Sources.7z
DevTools kit
SH2 Platforms
32x
Saturn

PowerPC Content
Learn PowerPC Assembly
Hello World Series
Simple Samples
PowerPC Downloads
PowerPC Cheatsheet
Sources.7z
DevTools kit
PowerPC Platforms
Gamecube

Work in Progress
ChibiAndroids

Misc bits
Ruby programming









Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!


























































































Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!



































































































Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!