Beyond Basic - Part 1
Written By: Tony Cruise
First Published: MSX and Spectravideo Computer Forum Vol. 2 No. 10
Introduction
What I aim to do in this series of articles is to provide an insight into machine code programming on your computer. The articles will take for granted that you know how to program in BASIC, but will not require knowledge of machine code. Full machine code listings will be included for the person who wants to know more, but they will not be necessary for understanding the article.
The series of programs will eventually add extra commands that you can use in your BASIC programs.
The sections will include:-
- Making use of all 64k of your computer’s memory
- Printer dump routines
- Screen save and load to memory and/or tape and disk
- Automatic sprite movement with velocities
- Sprite collision detection
- Screen scrolling routines
Part 1 – Using More Memory
A lot of the original MSX game titles that used more than 32K of RAM were very machine dependant. A classic example is “Finders Keepers” which only works on the Sony HIT-BIT. The author took it for granted that all of the MSX machines would have their RAM in the same area. To explain this further look at the diagram below:
0000H | Slot 0 | Slot 1 | Slot 2 | Slot 3 | |
ROM | SONY | Page 0 | |||
4000H | |||||
ROM | SONY | Page 1 | |||
8000H | |||||
ROM | SONY | Page 2 | |||
C000H | |||||
ROM | SONY | Page 3 | |||
FFFFH |
Any of the boxes in the picture can hold 16K of RAM or ROM (Up to 64K can be placed in each box, but that is beyond the scope of this article). Only one of the four slots can be activated for each page of memory. Thus when you turn on the computer the BASIC ROM is activated, so only the top 32K of RAM can be accessed. This is why you only get 28K of RAM free for your BASIC programs (The other 4K of RAM is used by BASIC as a storage space for system variables e.g. cursor position).
Machine Code Program
1 ORIGIN | ORG 08400H | ||
2 ; | |||
3 ; PROGRAM TO FIND EXTRA RAM IN MSX COMPUTERS | |||
4 ; | |||
F3 | 5 START | DI | ; Disables all interrupts |
DBA8 | 6 | IN A,(0A8H) | ; Get page settings |
4F | 7 | LD C,A | ; Store in C |
0603 | 8 | LD B,3 | ; Loop counter |
210000 | 9 | LD HL,0 | ; Memory location to test |
C5 | 10 LP1 | PUSH BC | ; Save BC |
79 | 11 | LD A,C | ; |
B0 | 12 | OR B | ; |
CB20 | 13 | SLA B | ; |
CB20 | 14 | SLA B | ; |
B0 | 15 | OR B | ; Calculate slot |
D3AB | 16 | OUT (0A8H),A | ; Send bank information |
C1 | 17 | POP BC | ; Restore BC |
3E01 | 18 | LD A,1 | ; |
77 | 19 | LD (HL),A | ; |
7E | 20 | LD A,(HL) | ; |
3D | 21 | DEC A | ; |
2802 | 22 | JR Z,EXIT | ; Is it RAM |
10EC | 23 | DJNZ LP1 | ; Do loop again |
78 | 24 EXIT | LD A,B | ; |
B1 | 25 | OR C | ; |
CB20 | 26 | SLA B | ; |
CB20 | 27 | SLA B | ; |
B0 | 28 | OR B | ; Calculate slot |
32E7FF | 29 | LD (0FFE7H),A | ; Store in 0FFE7H |
79 | 30 | LD A,C | ; Set pages to normal |
D3AB | 31 | OUT (0A8H),A | ; |
FB | 32 | EI | ; Enable interrupts |
C( | 33 | RET | ; Return to BASIC |
Basic Loader
10 CLS:CLEAR 200,&HCFFF:DEFINTA-Z:A=&HD00020 READ A$:IF A$ <> “@” THEN POKE A, VAL(“&H”+A$):A=A+1:GOTO 20
30 PRINT” INSERT TAPE/DISK TO SAVE PROGRAM”
40 PRINT” AND PRESS ANY KEY”
50 A$=INPUT$(1):PRINT:PRINT “ SAVING ....”
60 BSAVE”CAS:RAMSEL”,&HD000,A-1:REM Remove CAS: if using disk
100 DATA F3,DB,A8,4F,06,03,21,00,00,C5
110 DATA 79,B0,CB,20,CB,20,B0,D3,A8,C1
120 DATA 3E,01,77,7E,3D,28,02,10,EC,78
130 DATA B1,CB,20,CB,20,B0,32,E7,FF,79
140 DATA D3,A8,FB,C9
150 DATA @