Beyond Basic - Part 1

Downloads|Programming|Beyond Basic

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
RAM

 

Page 0

4000H

     
 

ROM

 

SONY
RAM

 

Page 1

8000H

     
 

ROM

 

SONY
RAM

 

Page 2

C000H

     
 

ROM

 

SONY
RAM

 

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 ORIGINORG 08400H 
 2 ;  
 3 ; PROGRAM TO FIND EXTRA RAM IN MSX COMPUTERS
 4 ;  
F35 STARTDI; Disables all interrupts
DBA86IN A,(0A8H); Get page settings
4F7LD C,A; Store in C
06038LD B,3; Loop counter
2100009LD HL,0; Memory location to test
C510 LP1PUSH BC; Save BC
7911LD A,C;
B012OR B;
CB2013SLA B;
CB2014SLA B;
B015OR B; Calculate slot
D3AB16OUT (0A8H),A; Send bank information
C117POP BC; Restore BC
3E0118LD A,1;
7719LD (HL),A;
7E20LD A,(HL);
3D21DEC A;
280222JR Z,EXIT; Is it RAM
10EC23DJNZ LP1; Do loop again
7824 EXITLD A,B;
B125OR C;
CB2026SLA B;
CB2027SLA B;
B028OR B; Calculate slot
32E7FF29LD (0FFE7H),A; Store in 0FFE7H
7930LD A,C; Set pages to normal
D3AB31OUT (0A8H),A;
FB32EI; Enable interrupts
C(33RET; Return to BASIC

Basic Loader

10 CLS:CLEAR 200,&HCFFF:DEFINTA-Z:A=&HD000
20 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 @