0% found this document useful (0 votes)
198 views

NEC8201A TechRef

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
198 views

NEC8201A TechRef

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 258

PC-8201A Technical Manual

First edition

Mar 15th 1984

NEC Corporation
Persona] Computer development division

--1 - .
.. ; ;a;. ~ "

IMPORTANT NOTICE
(1) All rights reserved. This manual is protected br
copyright. No part of this manual may be reproduced in
any form whatsoever without the written permission of the
copyright owner.

(2) All efforts have been make to ensure that the contents
of this manual are correct; however, should any errors be
detected, NEC would greatly appreceate being informed.
(3) NEC can assume no responsibility for errors· in this
manual or their consequences. The entire risk as to the
results of and performance of this manual is assumed by
you.

Cc) 1984 NEC Corporation


Personal Computer Development Division
Tokyo, Japan

2 -
The numeric notation and rules in illustration

In this manual, all numbers are expressed in Decimal


unless preceded by special radix prefix Ax. Ao ,AB and Ao.
AX, AO and AB represent hexadecimal, Octal and Binary numbers
respectively. For instance, AX1000 is hexadecimal number
1000, which is 4096 in Decimal. Similarly AO400 is octal
number 400, which is 256 in Decimal. AB10000000 is Binary
number 10000000, 128 in Decimal. AD is used to explicitly
tell that is the decimal number.

In the illustration, the upper side of the memory map


is near AXFFFF. So the part drawn below.another part is
allocated at lower address area.

----------------- AXFFFF
I
I
I A
I

----------------- Upper

I
I
: File A

--------------~--
I
I
l File B

Lower
V
-----------------
---------------- AX0000
Fig 0.1 The •File A• is located
upper the •File e·.
c·=· means ·skipped •• )

- 3 -
And the address and the pointers written in the
illustration points· the just above the line.
APOINT ---> AX8000

·,I

================= <Skipped)

---------------- <-- APOINT


("'X7FFF>

Fig 0.2 Pointer and its contents

- 4 -
Authors:

Chapter 2 -- 4
Mr.Youshiro Hayashi
Software Engineer
Ap~lication Technology Department
Personal Computer Sales Promotion Division

Chapter 1,5 -- 8

Mr.Hiroaki Yokoyama
Software Engineer
Development department
Personal Computer Development Division

Chapter 9 -- 14
Mr.Akio Takagi

Software Engineer
Development Department
Personal Computer Development Division

Chapter 15

Mr.Moriharu Seki
Hardware Engineer
Development Department
Personal Computer Development Division

Rewritten and edited by Mr.Hiroaki Yokoyama

- 5 -
CHAPTER 1 INTRODUCTION

CHAPTER 2 MEMORY MAP


2.1 OVERV I EU • • • • • • • • • • • • • • • • • • • • • 13
2.2 BANK SWITCHING ARCHITECTURE • • • • • • • • • • • 16
2.2.1 Bank Switching Hardware • • • • • • • • • • • • 17
2.2.2 Bank Switching Software • • • • • • • • • • • • 20
2.3 GENERAL MEMORY ·MAPPING OF INTERNAL SOFTWARE USE • 21
2.4 SAMPLE • • • • • • • • • • • • • • • • • • • • • • 25

CHAPTER 3 HOU TO USE 2ND ROM


3.1 CONSIDERATION OF INTERRUPT •••.•••••••• 28
3.1.1 Power Off Trap (ADDRESS AX4CFA) • • • • • • • • 29
3.1.2 Barcode Reader • • • • • • • • • • • • • • • • • 30
3.1.3 UART • • • • • • • • • • • • • • • • • • • • • 31
3.1.4 Interval Timer (ADDRESS AX1EBE With Disable
Interrupt) • • • • • • • • • • • • • • • • • • • 33
3.2 ROM SWAPPING METHOD • • • • • • • • • • • • • • • 35
3.3 THE METHOD TO USE 1ST ROM ENTRY FROM 2ND ROM ••• 36
3.3.1 Samp 1e • • • • • • • • • • • • • • • • • • • • • 37
3.4 SEQUENCES IN THE 2ND ROM • • • • • • • • • • • • • - 39
3.5 SUMMARY -- IMPORTANT NOTICE • • • • • • • • • • • 42
3.6 SAMPLE • • • • • • • • • • • • • • • • • • • • • • 44

CHAPTER 4 HO~ TO USE 2ND/3RD RAM


4.1 READ ANO WRITE TO ANOTHER RAM BANK ••••••• 51
4.1.1 Method 1 CUSING 1st ROMl • • • • • • • • • • • • 51
4.1.1.1 GETBNK CAX7EECJ • • • • • • • • • • • • • • • 51
4.1.1.2 PUTBNK CAX7EEBJ • • • • • • • • • • • • • • • 52
4.1.2 Method 2 CUSING YOUR ORIGINAL CODEJ • • • • • • 53

'iAPTER 5 UNDERSTANDING THE RAM FILE CONCEPT


5.1 SUMMARY • • • • • • • • • • • • • • • • • • • • • 60
5.2 WHAT IS RAM FILE? • • • • • • • • • • • • • • • • 62
5.2.1 DO Fi 1e <ASCII File) • • • • • • • • • • • • • • 62
5. 2. 2- BA File 66
5. 2. 3
5.2.4
co File •• •• •• •• •• •• ••
The Order Of The Files
• • • • •
• • • • •
In RAM •
• • •
• • •


• • •
• •. . •
• 74
75
• • • • • • • •

- 6 -
CHAPTER 6 DIRECTORY STRUCTURE
6.1 DIRECTORY CONFIGURATION PER ENTRY • • • • • • • • 76

CHAPTER 7 RAM ORGANIZATION


7.1 MEMORY MAP ABOUT RAM FILES • • • • • • • • • • • • 79
7.2 BOOKKEEPING AREA • • • • • • • • • • • • • • • • • 86
7.2.1 Part IC For RAM File Handling And BASIC> • • • 87
7.2.1.1 FS IDSV • • • • • • • • • • • • • • • • • • • • 88
7.2.1.2 HI MEM • • • • • . • • • • • • • • • • • • • • • 88
7.2.1.3 TXTTAB • • • • • • • • • • • • • • • • • • • • 89
7.2.1.4 STKTOP • • • • • , •• , • • • • , • • • • • . 89
1.2.1.5 DI RTBL • • • • • • • • • • • • • • • • • • • • 90
7.2.1.6 NULD IR • • • • • • • • • • • • • • • • • • • • 90
7.2.1.7 SCRO IR • • • • • • • • , • • • • • • • • • • • 91
1.2.1.a EOTOIR • • • • • • • • • • • • • • • • • • • • 91
7.2.1.9 USRO IR • • • • • • • • • • • • • • • • • • • • 91
7.2.1.10 BOTTOM • • • • • • • • • • • • • • • • • • • • 92
7.2.1.11 MEMS IZ • • • • • • • • • • • • • • • • • • • • 92
7.2.1.12 FRET OP • • • • • • • • • • • • • • , • • • • • 92
7.2.1.13 ASCTAB • • • • • • • • •. • • • • • • • • • • • 93
7.2.1.14 BI NTAB • • • • • • -. • • • • • • • • • • • • • 93
7.2.1.15 VARTAB • , • • • • • • , • • • • • • • • • • • 93
7.2.1.16 ARYTAB • • • • • • • • • • • • • • • • • • • • 94
7.2.1.17 STREND • • • • • • • • • • • • • • • • • • • • 94
7.2.1.18 FILTAB • • • • • • • • • • • • • • • • • • • • 94
7.2.1.19 NULBUF • • • • • • • • • • • • • • • • • • • • 95
7.2.2 Part II C VRAM Area For LCD> • • • • • • • • • 98
7.2.3 Part III ( Bookkeeping Area For BIOS) • • • • • 98
7.2.4 FCB (file Control Block) • • • • • • • • • • • • 99

CHAPTER 8 RAM FILE HANDLING


8.1 WHAT SHOULD WE 00 IN RAM FILE HANDLING • • • • • • 103
8.2 HOW TO MAKE NEW FILE • • • • • • • • • • • • • • • 106
s.2.1 How To Register The New File Name • • • • • • • 106
a.2.2 How To Make 00 File • • • • • • • • • • • • • • 106
8.2.3 How To Make A BA File • • • • • • • • • , ••• 109
8.2.4 How To Make A CO File • • • • • • • , • • • • , 111
8.3 HOW TO DELETE A FILE • • • • • • • • • • , • • • . 113
8.3.1 How To Delete A DO File • • • • • • • • . • , , 113
8.3.2 How To Delete A BA File • • • • , , • • • • • • 114
8.3.3 How To DELETE A CO File • • • • • • • • • • . • 117
8.4 HOW TO APPEND DATA TO DO FILE • • • • • • • • • • 122
8.5 HOW TO INSERT DATA TO DO FILE • • • • . • • • . • 123
8.6 HOW TO DELETE DATA FROM DO ·FILE • • • • . • . • • 124
8.7 USEFUL ROUTINES FOR RAM FILE HANDLING IN ROM #0 . 125

- 7 -
8.7.1 MAKHOL • • • • • • • • • • • • • • • • • • • • • 126
8.7.2 LNKFIL • • • • • • • • • • • • • • • • • • • • • 129
8.7.3 MASOEL • • • • • • • • • • • • • • • • • • • • • 132
8.7.4 CHEAO • • • • • • • • • • • • • • • • • • • • • 133
a.a SAMPLE PROGRAM ••••••••••••••••• 134
8.8.1 Make A New 00 File CASCii File) • • • • • • • • 135
8.8.2 Save Data Into 00 File • • • • • • • • • • • • • 139
8.8.3 DELETE SOME DATA FROM 00 FILE • • • • • • • • • 142
8.8.4 DELETE 00 FILE • • • • • • • ~ • • • • • • • • • 144
s.a.s DELETE BA FILE • • • • • • • • • • • • • • • • • 146
8.8.6 MAKE NEW CO FILE • • • • • • • • • • • • • • • • 149
8.8.7 DELETE A CO FILE • • • • • • • • • • • . • • • • • 152

CHAPTER 9 LCD INTERFACE


9.1 OVER VIEW • • • • • • • • • • • • • • • • • • • • 154
9.2 CONSTRUCTION OF LCD • • • • • • • • • • • • • • • 154
9.3 I/0 PORT RELATED TO LCD • • • • • • • • • • • • • 156
9.3.1 BLOCK SELECT --- PPI 81C55 PORT A/B • • • • ·156
9.3.2 LCD COMMAND SET • • • • • • • • • • • • • • • • 157
9.3.2.1 Display ON/OFF • • • • • • • • • • • • • • • • 157
9.3.2.2 Set Addr~ss Counter • • • • • • • • • • • • • 158
9.3.2.3 Set Starting Page • • • • • • • • • • • • • • • 160
9.3.2.4 Select Address Counter Mode • • • • • • • • • 162
9.3.3 Read Status --- Read The Status Of Segment
Driver. •· • • • • • • • • • • • • • • • • • • • 163
9.3.4 Uri te/Read Oisp 1ay Data • • • • • • • • • • • • 164
9.4 SOFTWARE FOR LCD • • • • • • • • • • • • • • • • • 165
9.4.1 How To Initialize The LCD • • • • • • • • • • • • 165
9.4.1.1 Sample Program For LCD Initialization • • • • • 166
9.4.2 How To Write A Character • • • • • • • • • • • • 168
9.4.2.1 Sample Program Of Uriting A Character On The
LCO. • • • • • • • • • • • • • • • • • • • • • 169
9.4.3 How To Set/reset A Dot On The LCD. • ., • • • • • 172
9.4.3.1 Sample Program For SET/RESET Dot. · • • • • • • 172
9.4.4 How To Define A Character • • • • • • • • • • • 177
9.4.4.1 Structure Of Character And How To Define It •• 177
9.4.5 How To Store The Your Own CG • • • • • • • • • • 179
9.5 AVAILABLE SYSTEM WORK AREA • • • • • • • • • • • • 180
9.5.1 How To Use The CG In System ROM • • • • • • • • • 180
9.5.2 VRAM AREA IN SYSTEM Uork Area • • • • • • • • • 182
9.5.3 Reverse The Attribute Of The Specified Area . • • 183

CHAPTER 10 KEYBOARD INTERFACE


10.1 THE KEYBOARD MATRIX • • • • • • • • • • • • • • • 184
10.1.1 I/0 Port For Keyboard • • • • • • • • • • • • • 186
10.1.2 KEYBOARD STROBE----- PART A/8 Of 81C55 • • • • 186

- 8 -
10.1.3 KEYIN ----- Read Keyboard Data • • • • • • • • 187
10.1.4- Keyboard Scanning • • • • • • • • • • • • • • • 188
10.2 SOFT WARE FOR KEYBOARD OPERATION. • • • • • • • • 189
10.2.1 How To Read The Keyboard • • • • • • • • • • • • 189
10.2.1.1 Sample Program Reading Keyboard. • • • • • • • 190

CHAPTER 11 ·CMT INTERFACE


11.1 HARDWARE FOR CMT •••••••••••••••• 193
11.1.1 Writing Operation • • • • • • • • • • • • • • • • 194
11.1.2 Reading Operation • • • • • • • • • • • • • • • • 195
11.1.3 Baud Rate Generation • • • • • • • • • • • • • . 196
11.1.4 I/0 Port For CMT • • • • • • • • • • • • . • • . 197
11.1.4.1 SCP---- SYSTEM CONTROL PORT •••••••• 197
11.1.4.2 PPI 81C55 Command Set • • • • • • • • • • • • 197
11.2 SOFTWARE FOR CMT • • • • • • • • • • • • • • • • • 199
11.2.1 CMT MOTOR CONTROL • • • • • • • • • • • • • • • 199
11.2.2 Baud Rate Generation • • • • • • • • • • ! • • • 200
11 • 2 • 3 Write A Oa ta To The CMT • • • • • • • • • • • • 201
11.2.4 Reading A Data From The CMT • • • • • • • • • • 203

CHAPTER 12 SERIAL INTERFACE


12.1 HARDWARE OF SERIAL INTERFACE • • • • • • • • • • • 206
12.1.1 I/0 Port • • • • • • • • • • • • • • • • • • • • 207
12.1.1.1 Channel Select - (Sy9tem Control Port) • . • 207
12.1.1.2 ·uART Mode Control • • • • • • • • • • • • • • 208
12.1.f.3 UART Status Read • • • • • • • • • • • • • • • 209
12.1.1.4 Set UART Baud Rate CPPI 81C55 Timer Section> • 210
12.1.1.S UART DATA I/0 Port • • • • • • • • • • • • • • 212
12.2 SOFTWARE DESCRIPTION • • • • • • • • • • • • • • • 213
12.2.1 How To Initialize Serial Port • • • • • • • • • 213
12.2.1.1 Sample Program••• How To Initialize SERIAC
Port • • • • • • • • • • • • • • • • • • • • • 214
12.2.2 SEND A Data To The Serial Port • • . • • • • • • 217
12.2.3 Read A Data From Serial Port • • • • • • • • • • 218
12.3 AVAILABLE SYSTEM AREA • • • • • • • • • • • • • • • 219

CHAPTER 13 BARCODE READER


13.1 ELECTRIC SPECIFICATION • • • • • • •• • • • • • • • 221
13.2 THEORY OF OPERATION • • • • • • • • • • • • • • • 222

CHAPTER 14 PARALLEL INTERFACE


14.1 HARDWARE SPECIFICATION • • • • • • • • • • • • • • 223

- 9 -
14.1.1 Physical Interface Of PC-8201A • • • • • • • • • 223
14.1.2 I/0 Port For PRINTER Interface • • • • • • • • • 223
14.1.2.1 Port A---- Data Out Put Port For Printer • • • 223
14.1.2.2 Port C ---- BUSY,SLCT Signal Read • • • • • • 224
14.1.2.3 SPCCSystem Control Port> --- STROBE Output
Po~t . • • • • • • • . • • . . . . • . . . . . 224
14.1.3 Basic Theory Of Writing A Data To Centronics •• 225
14.2 SOFTWARE SPECIFICATION • • • • • • • • • • • • • • 226
14.2.1 How To Write A Byte To Th~ Printer • • • • • • • 226

CHAPTER 15 HARDWARE
15.1 SYSTEM SLOT • • • • • • • • • • • • • • • • • • • 229
15.1.1 Assignment Of Signal • • • • • • • • • • • • • • 229
15.1.2 Explanation Of Pin • • • • • • • • • • • • • • • 232
15.1.2.1 Function Of Signal • • • • • • • • • • • • • • 232
15.1.3 DC Characteristics • • • • • • • • • • • • • • • 236
15.1.4 AC Characteristics • • • • • • • • • • • ~ • • • 237
15.2 MEMORY CONTROL CIRCUIT • • • • • • • • • • • • • • 240
15.3 I/0 ADDRESS • • • • • • • • • • • • • • • • • • • 245
15.3.1 Detail Information About I/0 • • • • • • • • • • 247
15.3.1.1 Reserve Area • • • • • ~ • • • • • • • • • • • 247
15.3.1.2 System Control • • • • • • • • • • • • • • • • 247
15.3.1.3 Bank Contro 1 • • • • • • · • • • • • • • • • • • 24.8
15.3.1.4 Bank Status • • • • • • • • • • • • • • • • • 249
15.3.1.5 PIO 81C55 Address • • • • • • • • • • • • • • 250
15.3.1.6 UART Data I /0 Port • • • • • • • • • • • • • • 254
15.3.1.7 UART Control Port • • • • • • • • • • • • • • 254
15.3.1.8 Keyboard Input • • • • • • • • • • • • • • • • 257
15.3.1.9 LCDC Address • • • • • • • .• • • • • • • • • • 257

- 10 -
CHAPTER 1
INTRODUCTION

The portable personal computer, PC-8201A is a unique


and practical computer. It has many special capabilities in
it. For example, it uses large LCD CLiquied Crystal Display),
CMOS (Complementary Metal Oxide Semiconductor) technology and
special built-in Software.

The built-in software features are very powerful a~d


useful. But for using PC-8201A fully in particular purpose,
new Software written in Machine language might be requested.
One of the built-in software, N82-BASIC is very useful to make
a small utility, but it's not enough to make a large size
utility, for instance, Spread Sheet or new Word Processor.

I~ order to support the programmers who want to make


such a large programs, and to support the programmers who want
to manage the hardware features directly, this document
describes ·not only the detail hardwa~e features of PC-8201A,
but also the know-how to use these features without any
trouble.

The most important thing is ·compatibility•. The


built-in Software features keep the promise in using the
memory, I/0 interface and interrupt functions. The built-in
Software checks many critical points at Power-on automatically
as far as you don't remove the ROM #0. So if you break the
promise, PC-8201A begins ·cold start· to initialize the all
contents in RAM. In this case, the important files and data
which-you stored are flushed.

The promise for using PC~8201A's features is described


in each chapter. Before making.a your special program, please

- 11 -
INTRODUCTION

refer to the corresponding chapters. The previous INDEX will


help you.

The built-in Software uses a small part of the


PC-8201A's special features. With this manual, may you make a
super programs for your own purpose!!

!
~- - 12 -
CHAPTER 2
MEMORY MAP

2.1 OVERVIEW
The PC-8201A has the following memory capacity. The
value specified with "Max" means the maximum capacity that is
greatly expanded by adding RAM/ROM chips or RAM cartridge.
ROM 32K byte~
C Max 64K bytes)
RAM 16K bytes
( Max 96 K: 32k bytes x 3 bank)
2 banks are equipped on Main
board of PC-8201A and 1 bank
is provided with RAM cartridge.

And PC-8201A has three useful programs in the standard


ROM, ROM #0. These programs are CN82->BASIC , TEXT and
TELCOM.

N82-BASIC: Microsoft BASIC, specialized


for PC-8201A.
TEXT: Simple and powerful word
processor
TELCOM: Communication program with
other digital computers
via RS-232C.

The simple memory map of PC-8201A is illustrated in

- 13 -
MEMORY MAP

the next figure. This illustration is a one of the standard


pattern. Refer to Chapter 15 ~o understand the hardware
expansibility, the detail configuration of memory and how to
change the memory configuration.

- 14 -
f
I
MEMORY MAP

Bank .0 Bank 1 Bank 2 Bank 3


AXFFFF -----------
RAM
STANDARD:
#1 CRAM CRAM
AXC000 ----------- #2) #3)
AXBFFF ----------
'
• I

RAM I
I
(option):
*1

AX8000 ----------- ---------- -----------


AX7FFF ----------- --------- ---------- -----------
ROM ROM RAM RAM
STANDARD:
#0 #1 *2 #3

0 ----------- -------- --------- ~--------


Main memory RAM cartridge
Fig 2.1 PC - 8 2 0 1 A ME MO R Y MA P

The RAM it2 and RAM i3 can be located both low


address, from 0 to AX7FFF, and high address, from
AX8000 to AXFFFF. This selection can be done by PORT.
access. Refer to chapter 2.3.

- 15 -
MEMORY MAP

2.2 BANK SWITCHING ARCHITECTURE

The heat of PC-8201A is the Intel 80C85, which is 8


bit processor and whose address bus is 16. Thus, the 80C85
can access 64K of memory at a time. In PC-8201A, however,
special memory access function called memory-bank switching is
supported. So the 64K barrier in 8-bit microprocessor can be
tricked in PC-8201A.
The RAM in the PC-8201A is divided into units referred
to as ·sANKs·. One bank can contain a maximum of 32K bytes of
memory, while the RAM can be expanded to hold a maximum of
three banks. CRAM #1, RAM *2, RAM #3)
The RAM #2 and RAM #3 can be located in two different
positions, lower position is from AX0000 to AX7FFF and higher
position is from AX8000 to AXFFFF) And RAM #3 is detachable,
because it is provided in RAM cartridge. The bank-switching
is executed every 32K bytes. For the sake of this limitation
it is impossible to access the half part of RAM #1 and half
part of RAM #2 at a time. In other words, you cannot set up
the this kind of memory allocation, lower half of RAM #2, from
AX8000 to AXBFFF, and higher part of RAM #1, from AXC000 to
AXFFFF as 32K of memory. The variety of memory allocation is
illustrated and explained kindly in Chapter 15. The
explanation about the software specification in bank-switching
is shown in the next section.

The RAM #2 and RAM #3 can be protected by a •PROTECT


SUITCH•. The •pRQTE-CT SWITCH• for RAM #2 is equipped at the
real panel. Refer to the page 1-3 in PC-8201A User's guide.
The RAM #3 has it at the side of the cartridge. But
unfortunately, RAM #1 has no such a protect function~ When
you use this protect switch, you cannot use that RAM bank in
usual way, for instance, BASIC. Because, PC-8201A uses the
highest RAM area, from AXF380 to AXFFFF to save the current
status of PC-8201A every time.

All RAM chips consists of CMOS and are back-uped by


battery. All data and program files stored in RAM will be
kept, even if the power switch is turned off._ If you make a
special utility for 2nd ROM or special RAM configuration, you
have to consider about this Power-down sequence. Refer to
chapter 3 to understand the Power-off trap in ROM #0.

- 16 -
MEMORY MAP

2.2.1 Bank Switching Hardware


The ·bank-switching· is· performed by OUT instruction.
The OUT instruction outputs 8 bit data to.the I/0 port. The
port address and that bit assign of the 8 bit data is shown
below.

PORT ADDRESS AXA1 (OUT)


Bank control

MSB 7 6 5 4 :· 3 2 1 0

Bit 7 not used


Bit 6 not used

5
.Bit not used
Bit 4 not used
Bit 3 High address
(AX8000 - AXFFFF) selection #2
Bit 2 High address

C"X8000 - "'XFFFF> selection #1


Bit 1 Low address
C"'X0000 - AX7FFF) selection #2
Bit 0 Low address
("X0000 - "'X7FFF> selection #1

- 17 -
F'
'
MEMORY MAP

High address #2 High address #1


0 0 Bank #0 CRAM #1)
0 1 not used
1 0 Bank #2 <RAM #2)
1 1 Bank 13 CRAM 13)
Low address #2 Low address #1
0 0 Bank #0 <ROM #0)
0 1 Bank #1 CROM #1)
1 0 Bank #2 CRAM #2)
1 1 Bank 13 CRAM #3)

- 18 -
MEMORY MAP

The current status of the memory, the status of


bank-switching, can be examined by IN instruction. The IN
instruction reads a 8 bit data from the specified I/0 port.
See next figure about the Port address and bit assignment of
the data.

PORT_ADDRESS ~XA0H CIN>


Bank status

MSB -----------------~-------------------------------
7 6 5 4 3 2 1 0

Bit 7 Serial interface status #2


Bit 6 Serial interface status +n
Bit 5 Not used
Bit 4 Not used
*2
Bit 3 --- High address C... X8000 - ""XFFFF> status
Bit 2 High address C... X8000 - ... XFFFF> status
ft1
Bit 1 Low address C... X0000 ... X7FFF> status
tt2
Bit 0 Low address C... X0000 - "'X7FFF> status
*1

Serial I/F #2 Serial I/F #1


0 0 Not used
0 1 SIO port
1 0 Floppy
disk port
1 1 RS-232C port

High address #2 High address #1


0 0 Bank #0 CRAM #1)
0 1 Not used
1 0 Bank #2 CRAM #2)
1 1 Bank #3 CRAM #3)
Low a·ddress #2 Low address #1
0 0 Bank #0 CROM #0)
0 1 Bank #1 CROM #1)
1 0 Bank #2 CRAM #2)
1 1 Bank #3 CRAM #3)

Refer to Chapter 12 about Serial Interface.

- 19 -
MEMORY MAP

2.2.2 Bank Switching Software

The bank-switching capability is used in Menu mode.


The •BANK• command, arranged in Function key 10 (Shift+ F.S)
uses this function. This function falls into the Bank handler
routine, CHGBNK, AX7EAB. The CHGBNK checks the current bank
status, tests whether the bank really exists, save the new
bank # in BANK (AXF308), changes the bank status and jumps to
the address 0. Jumping to address 0 causes ·coLO START• if
the bank has not ever used or the flag named FSIOSV has a
wrong value. (Refer to the section 3.2 Bookkeeping area.)
Otherwise, Jumping 0 does ·wARM START·.

In or.der to test the existence of the another bank,


CHGBNK reads the contents of the address, AXE000, in that
destination bank, modifies that value, restores it, and
re-reads it. If that bank were really in exist, the value
read first and the value re-read last are not identical.

The reason why CHGBNK jumps·into the address 0 is, you


might already notice, to set up the bookkeeping area. As
described in Chapter 7, all standard programs and operating
system uses this area every time to keep the current status.
This area contains very important pointers, flags and
interrupt routines. So without setting up this area, that
bank cannot be handled with ROM #0 correctly.

If you use a bank only with your - special application


program, which does not use the pointers on interrupt routines
in the bookkeeping area, you might think that you need not
care about the bookkeeping area. But please do not forget
that ·sHIFT+F.s• in menu level can change the bank any time.
I recommend that you will keep the current rules about
Bank-switching in ROM #0, and set up the bookkeeping area.

Refer chapter 4 •HOW TO USE 2ND/3RD RAM• to get more


detail documents.

- 20 -
MEMORY MAP

2.3 GENERAL MEMORY MAPPING OF INTERNAL SOFTWARE USE

You know that the ROM #0 addressed from 0 to AX7FFF is


used for standard programs and operating systems. (Sometimes,
·standard programs· represents BASIC, TEXT and TELCOM
especially. •operating system· also represents ·Menu·. But
there is no explicit border line between the ·standard
programs· and ·operating system·. But I do sometimes use
these words to explain the concept of the PC-8201A's built-in
software.) Also, Some parts of the RAM memory area are
reserved and used by that standard programs and operating
system. The memory map about the RAM area is figured at next
page. The each part of the - reserved area is pointed by
pointers in the ·book-keeping area·, located at the highest
part of the RAM memory, from AXF380 to AXFFFF. And the
following 2 items are included in the book-keeping area, too.

Interrupt routine
System work area

- 21 -
MEMORY MAP

Fig 2.2 PC - 8201A RAM AREA MEMORY MAP


AXFFFF -----------------I
: Bookkeeping I
·I
ar-ea I

AXF3s0· -------------~---I
· : User- machine I

stored ar-ea :<- CHIMEMJ "'XF384


: File control I
I
: block ar-ea :<- CFILTABJ "'XFB63
: 2 Bytes space:
: String ar-ea : <- CMEMSIZJ "'XFA9A
(used)

: String ar-ea : <- CFRETOPJ "'XFABF


(fr-ee)

: Staci< ar-ea :<- CSTKTOPJ "'XF459


:<- Stack Pointer-
I I
I Fr-ee ar-ea I

:<- CSTRENDJ "XFAE9


-----------------
I
I Ar-r-ay stored I
I

ar-ea :<- CARYTABJ "'XFAE7


-----------------
Simple I
I

variable ar-ea :<- CVARTABJ "XFAES


.co files I
I

ar-ea :<- CBINTABJ "'XFAE3


-----------------
: EDIT ar-ea I
I

: for- BASIC :<- CEOTDIRJ+1 "F886+1


: Paste buffer- I
I

: for- TEXT :<- CSCRDIRJ+1 "XF87B


: .DO files I
I

ar-ea : <- ~ASCTABJ "'XFAE1


: non-registered:
l BASIC file :<-CNULDIRJ+1 "'XF870+1

- 22 -
MEMORY MAP

: .BA fi 1es
ar-ea : <-CTXTENDJ "XFA88
: Cur-r-ent BA
file l<-CTXTTABJ "XFASO
: .BA fi 1es I
I
ar-ea l<-CBOTTOMJ+1 "XF980+1
I <-CBOTTOMJ "XF980

- 23 -
MEMORY MAP

Brief explanation about pointers which appear at the


previous page.

CBOTTOMJ Bottom address of RAM


CTXTTABJ Beginning of the current BASIC program
CTXTENOJ End of the current BASIC program
CNULOIRJ Non-registered BASIC program
· CASCTABJ Lowest address of ASCII files
CSCROIRJ SCRAP file
CBINTABJ Lowest address of binary files
CVARTABJ Simple variable space
CARYTABJ Start of array table
CSTRENOJ End of Array table
CSTKTOPJ Top of stack space
CFRETOPJ Top of string free space
CMEMSIZJ Highest location in memory
CHIMEMJ Highest memory available to BASIC
(The same as CLEAR's 2nd parameter)
rf. Chapter ·5 •uNOERSTANOING THE RAM FILE CONCEPT•,
·otRECTORY STRUCTURE• and •RAM ORGANIZATION•. In
those chapters, the concept of the files and detail
explanation about the pointers are described.

- 24 -
MEMORY MAP

2.4 SAMPLE

TITLE Bank switching pro~ram

;
,• This sample will only change the bank of
; RAM addressed from AX8000 to AXFFFF.
; · You had better check that the bank which
; you want to switch really exists. And you
,• should save the next bank# at the
,• bookkeeping area, BANK •
,•
,• Entry None
,• Exit None
,• Bank will be changed
,•
; Bank rotation #1 -> #2 -> #3 -> #1 ~> •••

; <<< SYSTEM labels>>>


SYSTEM EQU AX0000 ; Reset address
CONTRL EQU "'X0A1 ; Bank control port
STATUS EQU "'X0A0 ; Bank status port
; ·<<< Bank switching program>>>
ORG "'X0100 ; This program must be
; stored between "'X0000
; and AX7FFF
CHECK: DI ; Disable interrupt
IN STATUS ; Read current bank status
MOV B,A ; Save current bank status
ANI "'B00001100 ; Pick up high bank status
,• only
NEXTB:
ADI "'800000100 ; Set next bank data
CPI "'B00000100 ; This pattern was not used!
JZ NEXTB ; Set up next bank data
; for lap around
MOV C,A ; Save new bank data
MOV A,B ; Remember old bank status
ANI "'811110011 ; Do not change bit data
,• without RAM bank data·
ORA C ; Set new RAM bank
OUT CONTRL ; Select bank

- 25 -
MEMORY MAP

EI : Enable interrupt
JMP SYSTEM : We must update book
•• keeping area •
: Jump AX0000 is the
END •• best way •

- 26 -
CHAPTER 3
HOU TO USE 2ND ROM

When you want to make some programs stored in 2nd ROM,


there are a lot of matters should be attended and stored in
the 2nd ROM. The matters are interrupt jump tables and power
on/power off sequences. You have to implement these tables
and sequences in order to process the ROM bank switching
smoothly. Otherwise, PC-8201A will run away on switching the
ROM bank. First half sections describe the interrupt
functions and power sequence.
And you have to know the rules to handle the files and
data in ·RAM, too. If you will use the routines in ROM #0 to
handle the RAM, you need not to care about the detail rules.
(You can get the information about the RAM file handling
routines in ROM #0 at the Chapter 8 and another technical
manual that has already been available by NEC HE in Chicago.
Please request it if you have not gotten it yet.) The last
half of this chapter describes how to use the routines in ROM
#0 from 2nd ROM, ROM *1· (Hereafter ROM #1 sometimes
represents 2nd ROM.)
If you want to make I/0 control routines and store
them in 2nd ROM, you have to understand Chapter 9 to 14. If
you utilize the ROM #0's I/0 routines, the last half of this
chapter and another manual will help you.

- 27 -
,_, ..

HOU TO USE 2ND ROM

3.1 CONSIDERATION OF INTERRUPT

Basically, PC-8201A has some interrupt service


routines in that system. The main purpose of. interrupts are
smooth processing in Power off trap, reading data from
Bar-code reader, communicating through UART(RS-232C) and using
Interval timer.

The interrupt table is located in the zero page area.

POUER OFF TRAP NMI "'X0024


BARCODE READER RST 5.5 '"'X002C
UART RST 6.5 ""X0034
INTERVAL TIMER RST 7.5 "'X003C

The Interval timer interrupt has the highest priority,


and UART has the second one. The lowest interrupt is used for
Barcode reader. The reason why the internal timer has the
highest priority is to scan the key and to co~nt the
auto-power off counter for saving the battery power. PC-8201A
has the ·Auto-Power Off• function·. Usually, this function is
executed after 10 minutes has past since last key stroke was
detected. (This interval can be set by the •pouER• command in
BASIC. Refer •pc-8201A Reference Manual •• ) The interval .time
is used to count this period.

The interrupt hook table is located from ""XF386 to


"'XF394. And that table is constructed in the following fig.

Interrupt hook table in RAM area


"XF386 POWER ON SEQUENCE
"XF389 BARCODE READER INPUT SEQUENCE
"XF38C UART INPUT SEQUENCE
"XF38F TIMER SEQUENCE and KEY
SCANNING SEQUENCE
'"'XF392 POWER FAILURE SEQUENCE

- 28 -

/
HOW TO USE 2ND ROM

3.1.1 Power Off Trap (ADDRESS "'X4CFA>

This interrupt is Non maskable. When power switch is


turned off, this interrupt occurs. The following sequence is
the algorism of this interrupt.

1: Disable the interrupt


2: Call hook table
3: Reset Key wait counter
4: Cancel Time counter
5: Out a data to the.Auto power off port
6: HLT

The detail bit assignment of the auto power off port 1s


following.
PORT ADDRESS "'XBA <OUT>
81CS5 port B

MSB 7 6 5 4 3 2 1 0

Bit 7 RTS output


Bit 6 DTR output
Bit 5 BELL
0:Ring be 11
1:Stop be 11
Bit 4 Auto power off
0:0ff
1:0n
Bit 3 DCO/RO select
Bit 2 Melody control
0:0n
1:0ff
Bit 1 LCD chip select #1
Bit 0 LCD ch1p· select #0

rf.Chapter 9 to 15 about more detail information of


this port.

- 29 -
~-
t
HO~ TO USE 2ND ROM

3.1.2 Barcode Reader

(ADDRESS AXF389 with Disable interrupt)

This interrupt is using RST 5.5. If you do not use


barcode· reader program, this interrupt should do "RETURN"
soon.

- 30 -

,,-
HOW TO USE 2ND ROM

3.1.3 UART

(ADDRESS AX6E00 with Disable interrupt)

This interrupt is using RST 6.5. This interrupt is


caused by UART. (Serial communication device 6402) This
interrupt occurs when the data in 6402 receive buffer is
available.

The algorism of this interrupt is shown below.


1: Disable the interrupt
2: Call hook table
3: Read data from 6402
4: Read error status from 6402
S: Xon/Xoff control check
6: SI/SO control check
7: Return to previous process
PORT ADDRESS AxDs couT>
UART control port

MSB 7 6 s 4 3 2 1 0

Bit 7 Not used


Bit 6 Not used
Bit- S Not used
Bit 4 Character length select ~2
Bit 3 Character length select #1
Bit 2 Parity inhibit
0:Parity generation Check
11Parity generation check,
Inhibit
Bit 1 Even parity enable
0:0dd parity
1:Even parity
Bit 0 Stop bit select
0:Stop bit 1 bit
!:Stop bit 1.5 bit
in case of DATA Length 1s 5
!:Stop bit 2 bit
1n case of DATA Length
is not 5

- 31 -
f HOY TO USE 2ND ROM

PORT ADDRESS "'XCS (OUT)


UART data I/0 port

MSB
-----------------~-----------------------------
7 6 5 4 3 2 1 0
----------------------------------------------
Bit 7 Data #7
Bit 6 Data #6
Bit 5 Data *5
Bit 4 Data #4
Bit 3 Data #3
Bit 2 Data #2
Bit 1 Data *1
Bit 0 Data *0

rf. Chapter 12 and 15 about more detail information


about UART.

- 32 -

,,,-
HOW TO USE 2ND ROM

3.1.4 Interval Timer (ADDRESS AX1EBE ~ith Disable Interrupt)

This interrupt is using RST 7.5. This is the


interrupt from interval timer. (Timer device 1990) This
·interrupt is also used for the key scanning.
In the system's initialization, the interval timer
which is controlled by 1990, is set up as 4m second mode. The
port for 1990 is illustrated below.

PORT ADDRESS

Calendar clock (1990) control port

MSB 7 6 5 4 3 2 1 0

Bit 7 Not used


Bit 6 Not used
Bit 5 Not used
Bit 4 Data output
Bit 3 Shift clock
Bit 2 Command output i2
Bit 1 Command output #1
Bit 0 Command output #0
Command #2 Command #1 Command #0
1 0 0 timing 64Hz
1 0 1 Timing 256Hz
1 1 0 Timing 2048Hz
1 1 1 TEST mode

In the initialization routine, the command is set .UP


as AX05. It means 4m second interval.

rf. Chapter 15 for more information about 1990

The follow¼ng step is the algorism about interval


timer sequence.

- 33 -
HOW TO USE 2ND ROM

1: Disable the interrupt


2: Call hook table
3: Maek RST 7.5,RST 5.5
4: Reverse cursor character for cureor blink
5: Key matrix scanning
6: Return to the interrupted process

- 34 -

/
HOW TO USE 2ND ROM

3.2 ROM SWAPPING METHOD

When you would like to use 2nd ROM, you must write the
following information into the· 2nd ROM's special reserved
area. The special reserved area is located from AX0000 to
AX0047. These area will be used for 2nd ROM starting jump
instruction and IO code, and the file name of 2nd ROM. This
name is displayed like a one of the RAM files on Menu screen
by 1st ROM, ROM #0. The following figure is the explanation
about 2nd ROM special reserved area.

ADDRESS CODE
AX0000 JMP START ,• 2nd ROM start address
AX0003 • • • •
AX0024 RET ,• Non maskable interrupt
AX002C RET ,•
Barcode reader interrupt
AX0034 RET ,•UART interrupt
AX003C RET ,•Interval timer interrupt
AX003F ,•Reserved for RST interrupt
AX0040 DB 'A'
AX0041 DB '8' ,• IO code for 2nd ROM
AX0042 DB '2NDROM'; File name which displayed in
,• the menu
AX0048 START: ; 2nd ROM code
S P E C I AL R E S A R V E 0 ADORE S S

If these data are implemented correctly, the name will


appears on the 1st ROM's menu screen. So it's easy to switch
the ROM and execute the program in it. When you want to start
the programs in 2nd ROM from the Menu mode of ROM #0, move the
cursor to 2nd ROM's file name on the screen. Then please
press return key. The system will fall into the 2nd ROM
program.

- 35 -
HOW TO USE 2ND ROM

3.3 THE METHOD TO USE 1ST ROM ENTRY FROM 2ND ROM

If you want to use the routines in 1st ROM from 2nd


ROM, at the first, you have to create a special routine in the
higher memory location of RAM (AX8000-AXFFFF> and use it. That
routine swltches the ROM bank with using bank switching method,
and calls the routine in 1st ROM. It is very important for you
that the interrupts must be disabled before you change the ROM
banks. And in addition, as the following sections will tell
you, you have to change the hook table for Power down interrupt
that was changed by 2nd ROM to restart the current process in
2nd ROM program at next power-on. With this hook table for 2nd
ROM, the power down in ROM #0 will cause the fatal error.
Power-off interrupt can not be prohibited. And you have to
consider about the contents of the routine which you will call.
The reason is that some routines in the 1st ROM routine may
enable the interrupts in some parts of their code even if you
disable the interrupts just before switching the ROM banks to
call 1st ROM entry. Therefore you had better change the all
hook tables in the current book keeping area. I suggest that
all hook table should be replaced with previout contents which
were stored by 1st ROM, just before calling ROM bank-switching
routine ,and.restored just after coming back from 1st ROM.

The following program is the sample which uses 1st ROM entry
points from 2nd ROM.

- 36 -
HOW TO USE 2ND ROM

3.3.1 Sample
,• TITLE Using 1st ROM entry from 2nd ROM
,•
,•
; This sample will enable to use 1st ROM entry from
; 2nd ROM.
; ·Some routines in 1st ROM might enable interrupts,
; so all interrupt
; hook table should be replaced with RET code.
; And restore them after done the 1st ROM calling •
,•
• Entry CENTRYJ:1st ROM entry address
',• Exit for return condition of 1st ROM
,•
; <<< SYSTEM define label >>>
BNKCRL EQU "X0A1 ; Bank control port
STATUS EQU "X0A0 ; Bank status port
; <<< Main routine>>>
ORG "X8000 ; This routine must be stay
,• "X8000-~XFFFF
ROM1ST: SHLD WORKH ; Save register HL
LXI H,RET2NO ; Return address from 1st ROM
PUSH H ; Push stack top
LHLD ENTRY ; Pick up 1st. ROM entry
; address
PUSH H ; Push stack top
LHLD WORKH ; Restore HL
PUSH PSW ; Save all register
DI ; Disable interrupt
IN STATUS ; Get current bank status
ANI "811111110 ; Switch 1st·ROM data set up
OUT BNKCRL ; Bank select
; Now "X0000-"X7FFF are
; 1s·t ROM
EI ; Enable.interrupt
POP PSW •
RET ;' Jump 1st ROM entry
.' <<<Return from 1st ROM>>>
RET2NO: PUSH PSW . Save a 11 register
IN STATUS '• Get current bank status
ORI "'B00000001 ' Switch 2nd ROM data set up
OUT BNKCRL •Bank select
'•Now "X0000-"X7FFF are
'•2nd ROM
POP PSW ' Pick up a 11 register

- 37 -
HOW TO USE 2NO ROM

RET ,•
; <<< SYSTEM WORK AREA>>>
ENTRY: ow AX0000 I 1st ROM entry address
WORKH: OW AX0000 ; HL register saving area
END

- 38 -
HOW TO USE 2ND ROM

3.4 SEQUENCES IN THE 2ND ROM

1. INITIALIZE
This sequence sets up CSPJ(Stack Pointer),
power-on trap and other interrupt routines. Then it
copies the book-keeping area and system area. finally
some peripherals will be initialized by this routine.

2. RETURN TO MENU

At the first, this sequence selects the standard


RAM, RAM #0 and resets the power-off trap. Then it jumps
to 1st ROM's menu mode.

3. POWER DOWN

When power is turned off, the control is


transferred to this sequence. In this sequence, you must
save all registers and circumstances which should be saved
in the stack. So the stack-pointer is most important to
resume the current processing on the next power-on.
The RAM bank number is always stored in RAM #0. On
turning on, the 1st ROM and RAM #0 is selected
automatically. And the bank-switching procedure will be
called in Power on sequence if t~e number of the RAM bank
was not identical to the RAM #0 in the powe~ down
sequence. After changing the RAM bank, all registers will
be restored and pending· procedure will be resumed.
Therefore in the stack, the address of the process which
was abandoned by Power down trap should be stored.
In addition, in order to resume the abandoned process
with 2nd ROM, you have to do special power on/power off
sequence. In power off trap, you should the set the start
routine of the special power-on sequence which switches
the ROM bank. I recommend to use the hook, AXF38F.
Usually, •JUMP to POWER FAIL SEQUENCE• command is st~red
here. In 2nd ROM, however, you have to rewrite this hook
table and call the special power down routine here. In

- 39 -
t.
' HOW TO USE 2ND ROM

it, the address of special power-on routine on the stack.


In this case, the following information should.be stacked
before •HLT• command is executed.

resuming address

starting address of
the ROM switching
routine
Contents of Pointers
<-- CS°TAKSVJ

CSTAKSVJ keeps the SP's value at •HLT·.


Fig 3.1

4. POWER ON

At the first, .the initializing routine in ROM #0


checks the RAM bank number in BANK (AXF308) when power-off
was exe~uted. When power-off was done in non-standard RAM
bank, RAM bank-switching routine is called and switched.
Then, the registers' contents will be restored. If the
address of the process which should be resumed was
stacked, the address will be picked up and executed. When
the power-down was detected in ROM #1, the address of the
special ROM switching routine ought to be stacked above
the address of the process should be resumed. Therefore,
after switching the ROM, the abandoned process will be
resumed.

- 40 -
HOW TO USE 2ND ROM

The following figure are the general 2nd ROM routine control
sequence.

: MENU mode
. ROM:
of 1st

:- select 2nd ROM


I
I
V
---------------------------------------~---
:--------------
INITIALIZE RETURN

:-Return
I
I

: Main routine of 2nd ROM

I
I
+-Turn off power switch:

POWER DOWN : . POWER ON .

...
:-Turn on
power switch
V

P O WE R 0 F F

Fig 3.2

- 41 -
rJ
r HOW TO USE 2ND ROM

3.5 SUMMARY -- IMPORTANT NOTICE

If you want to make 2nd ROM program, you should take


care of the following manner.

1. Interrupt vector
If you do not want to use interrupt, all interrupt
table should be set with only ·RET• code. But I suggest
you that you had better use interval timer interrupt,
because of saving the battery poWer by using auto power
off function. The counter for this auto power off
function is counted by this interval timer interrupt. If
you do not use this function, the battery consumption may
be more larger than now.

2. Bank of RAM
Do not switch the ROM bank when PC, Program
Counter, points a routine in that ROM. You can guess the
reason and it's not so hard to imagine these bank
switching will cause the fatal problem for system. At the
worst case, the all files which you stored will be lost.
And also you should be careful in stack area, too.

3. PC-8201A book keeping area


The book keeping area are very important for this
system, so you never change that area without careful
consideration. Please read Chapter 7 ·aoOK KEEPING AREA•.

4. Power on/off sequence


Please use power off interrupt to detect the power
down. I suggest that you had better use the real time
interrupt service.to poll the power down signal.

- 42 -
HOW TO USE 2ND ROM

If you want to use 1st ROM entry from 2nd ROM, please
take care of the following point. The all routines rewrite
some work area sometimes. So, if you use 1st ROM entry from
2nd ROM witho~t understanding that routine's internal
specification, the system might be crashed. In addition,
interrupts and ·stack area are other important points. Refer
to 2.3 •The method to use 1st ROM Entry from 2nd ROM• and its
sample program.

- 43 -
HOU TO USE 2ND ROM -

3.6 SAMPLE

TITLE 2nd ROM sample header and useful routine

; <<< SYSTEM define label >>>


BANK EQU "'XF3DB ; Bank save area
ATIDSV EQU "'XF382 •
PWHOK EQU "'XF386 ':Power on hook table
RST55 EQU "'XF389 ; Rst 5.5 hook table
STAKSV EQU "'XF9AE •
AUTOID EQU ""X9C0B •'
SAVSTK EQU "'XFA00 '•
STATUS EQU "'XA0 ;' Bank status
BNKCRL EQU "'XA1 : Bank control
PWPORT EQU "'XB8 ; 81C55 chip select
PORTS EQU ""XBA ; 81CSS port 8
FREE EQU "'X???? ; You must set your ram
: free portion address
; <<< Main routine>>>

START:
JMP INIT : 2nd ROM start address
ORG "'X0024 ; Non maskable interrupt
: table
JMP POWER ; Power down trap
ORG ""X002C ; RST S.5
JMP BARCOO ; Barcode reader interrupt
: table
ORG "'X0034 ; RST 6.5
JMP UART ; UART interrupt table
ORG "'X003C ; RST 7.5
JMP TIMER ; Timer interrupt table
ORG "'X0040 ; IO code for 2nd ROM
OB 'AB' ; AB is ID code for 2nd ROM
DB '2NOROM' ; File name which
; displayed in the MENU
; <<< Initialization of 2nd ROM program>>>
!NIT: LHLO SAVSTK ; Set stack pointer

- 44 -
HOW TO USE 2ND ROM

SPHL ,•
CALL SETTRP ; Set hook for resume
; 2nd-ROM's program,
; and other routine into RAM.
CALL HINIT ; Hardware initialization
JMP MAIN ; Goto main routine
,•
; <<< Hardware initialize routine>>>
HINIT: RET ;

,•'
; <<< MAIN ROUTINE OF 2ND ROM>>>
,•
,•
MAIN: ; Main routine
; <<< Set up hook>>>
; Set up hook table for 2nd ROM
SETTRP: MVI A,"'800000001 • Select standard RAM
OUT BNKCRL '• Select!
LXI H,DTBL •' Set some codes into RAM
LXI D,PWHOK '•, for power on sequence
MVI B,TBLEND-DTBL •,
CALL COPY ,•
LXI H,TBLHOK ,• Return code table
.LXI D,FREE ,• Free area of RAM portion
LXI B,HOKE-TBLHOK • Set length
CALL COPY ,'•
RET ,•
,• CDEJ <- CHLJ
COPY: MOV A,M • Read CHLJ
STAX 0 •,' Save CDEJ
INX H •
INX D ',• Next address set
OCR B ,• Decrement counter
JNZ COPY ,• Loop until done
RET ,•

;' The following code will be copied in RAM
; portion for re-power on sequences
; these part are interrupt hook table •
,•
DTBL EQU $
MVI A,'"'800000001 ; These code will be
; copied into RAM
OUT BNKCRL ; Bank select!

45 -
~
v HOW TO USE 2ND ROM

JMP Pl.JON ; Jump power on trap


BANK!: OS 1 ,•
TSLENO EQU $

; -
; The following code will be copied
; in RAM portion for return 1st ROM
,•
TBLHOK EQU $
RETSB: XRA A ; Clear A
OUT BNKCRL ; Select 1st ROM and
; standard RAM
JMP "'X0000 ; Return!
HOKE EQU $

; <<< RETURN >>>


RETURN: MVI A,"'800000001 ; Select standard RAM
OUT BNKCRL ,•
MVI A,"B00000000 ,•
STA BANK ,•
LXI H,"'X0000 ; Reset
SHLD ATIOSV ,•
LXI H,RTBL ; Rewrite code table
LXI O,PWHOK ; Interrupt hook table set
LXI B,RTBLE-RTBL ; Set length
CALL COPY ,•
JMP RETSB ; Return to 1st
; ROM's menu mode
,•
; The following code will be copy
,• in standard ram portion • •

'
RTBL EQU $
RET ; Power on hook
NOP
NOP
EI ; RST S.S hook
RET
NOP
RTBLE EQU $

; <<< Power on >>>


PWON: CALL HINIT •,
LOA BANKI-DTBL ; Select old RAM bank
OUT BNKCRL •
LHLD STAKSV '; Restore stack pointer
SPHL ,•
POP PSW ,•
POP 8 •,

- 46 -
HOW TO USE 2ND ROM
.
POP 0 ,•
POP H ,•
RET ; Resume old program
; <<< POWER DOWN TRAP >>>
POWER: PUSH PSW ,•
IN PWPORT ; Read power down port
ANA A ; Check
JM NTPWFL ; No power down
POP PSW ,•
DI ; Disable interrupt
PUSH H ; Save HL
PUSH 0 ; Save DE
PUSH 8 ; Save BC
PUSH PSW ; Save AF
LXI H,"X0000
DAO SP ; Now I know stack address
SHLO STAKSV ; Save stack
MVI A,0FFH ; Reset interva 1 ·timer
; counter
STA PWRINT ; Set up for next power on
IN STATUS ; Save current RAM bank status
; When power on resume,
remember
; this and select RAM bank.
MOV 8,A ; Save it
MVI A,"800000001 ; Select standard RAM
OUT BNKCRL ; Select!
MOV A,B ; Resave old status
STA BANKI-OTBL ,•
MVI A,"S00000001 ; Select RAM bank 1
OUT SNKCRL •,
MVI A,0 ; Set up to come back
; to 2nd ROM
STA BANK •
LXI H,AUTOIO ',•
SHLD ATIDSV ,•
IN PORTS ,•
ORI "800010000 ,•
OUT PORTS ,•
HLT ; Never 90 on
•,
NTPWFL: POP PSW
RET ,•

; <<< BARCOOEREAOER interrupt>>>


BARCOO: RET ; Return soon
; <<< UART interrupt>>>

--47 -
HOW TO USE 2ND ROM

UART: RET ; Return soon


; <<< Interval Timer interrupt >>>
TIMER: LOA PWRINT ; Pick up timer value
OCR A ; :oecrement ! !
STA PWRINT ; Save it
RET ;
; <<< System work area>>>
PWRINT: 08 AX0FF ; Timer counter n * 1/256Hz
ENO

- 48 -
CHAPTER 4
HOW TO USE 2ND/3RD RAM

When you want to change the bank of ~AM, the most


simple method is to do OUT instruction and to jump AX0000 for
warm start. Because book keeping area management is too
difficult to do by yourselves, I think. But if you would not
1 ike to do war·m start, you must manage the book keeping and
system parameter by yourself and use the spe~ial RAM bank
handling routine. You can easily guess that when the bank of
RAM is changed, PC, the program counter must stay lower than
'"'X7FFF. Because bank switch is completely change the code of
-RAM which address '"'X8000 to '"'XFFFF. But the area from AX0 to
'"'X7FFF is used for ROM. The only one way is to make a special
RAM bank switch routine in all RAM banks with same address.
The following illustration will help you to understand. this
curious method.

POP HL POP HL ;Pick up return address


MOV A,NEXT MOV A,NEXT ;set next bank status
OUT '"'XA1 OUT '"'XA1 ;change bank
PUSH H PUSH H ; set return address
RET ;return to specified addres
RAM #0 RAM #1
Fig 4.1

Same routine is stored in the same position of 2 RAM banks •


. Refer to next
section to write a program at another bank.

- 49 -
HOW TO USE 2ND/3RD RAM
·- STACK POINTER ,too.
In addition you must take care of the

- 50 -
HOW TO USE 2ND/3RD RAM

4.1 - READ AND WRITE TO ANOTHER RAM BANK

These are two methods to read /write another bank of


RAM. The first is more simple than second one. But the first
method is some limitation of that performance, because this
method ·uses ROM #1. And the second method is more complex,
but this is more powerful. The size of the second method is
longer than the first one.

4.1.1 Method 1 CUSING 1st ROMJ

These are very useful routines in the 1st ROM. These


are GETBNK and PUTBNK.

4.1.1.1 GETBNK CAX7EECJ

This routine reads one byte from other banks of RAM.


The GETBNK routine temporarily changes the specified RAM bank,
reads a byte pointed by CHLJ, and returns to the original
bank. Interrupt should be disabled before calling the GETBNK
routine.

Entry CBJ = Bank number


AX00:Main bank
AX08:Bank #2
AX0C:Bank #3
CHLJ = Address which byte to read
Exit CDJ = Byte data which read
Altered registers
CAJ,CCJ,CDJ,CFJ

- 51 ~
HOU TO USE 2ND/3RD RAM

4.1.1.2 PUTBNK CAX7EESJ

The PUTBNK routine writes one byte at the specified


address pointed by CHLJ in the specified RAM bank. Similar to
the GETBNK routine, original bank will be. selected after
writing that data. Before using the PUTBNK routine, interrupt
should be disabled.

Entry CBJ = Bank number


"'X00:Main bank
"'X08:8ank #2
"'~0C:8ank #3
CHLJ = Location where the byte is stored
COJ = Byte data to be stored
Exit None
Altered registers
CAJ, CCJ, CFJ .

- 52 -
HOW TO USE 2ND/3RD RAM

4.1.2 Method 2 CUSING YOUR ORIGINAL COOEJ

When your code is located in upper address


(AX8000-AXFFFF), and you want to read/write a lot of data in
another· bank of RAM, you had better change the target RAM bank
at the lower position of the memory.

(1) Your c6de 1s in RAM #1. And data you want to


read or write 1s in RAM #2.

AXFFFF -------- --------


Your RAM
code #2

AX8000 -------- --------


AX7FFF --------
ROM

AX0000 --------
Fig 4.2
(2) Change the Bank.

AXFFFF ---------
Your
I
code I
I
I
I
:<--
I •·

AX8000 -------- Handle


AX7FFF --------- some
'
I data
RAM 12:
I
I

:<--

Fig 4.3

- 53 -
~···

HOU TO USE 2ND/3RD RAM

(3) Then change again into previous


Bank configuration.

In this case, _you have to disable to all interrupts


before changing the BANK.

- 54 -
HOW TO USE 2ND/3RD RAM

When your code is · located lower addres


(AX0000-AX7FFF), for instance, running a program in 2nd ROM,
please use next method to handle the data in other RAM banks.

(1) The program in 2nd ROM is running with RAM #1.

AXFFFF ---------- --------- \


:standard:
I
I RAM
: RAM *2
AX8000 ---------- --------- .
,

AX7FFF ----------
2nd
ROM

AX0000 ----------
Fig 4.4

(2) Read or Write RAM *2 by bank switching


during all interrupts prohibited.

~XFFFF ---------- -----------


RAM : RAM
#2 :standard
I
I .

AX8000 ---------- -----------


AX7FFF ----------
2nd
ROM

AX0000 ----------
Fig 4.5
(3) S~itch again, and resume the previous processing.

55 -
3RD 'RAN

TITLE Read Write routine·for another BANK of RAM

This sampl·e will access another bank of RAM.


There are two routines in this source program.
,. .The another one
One is having access in byte by byte by using
is to access in block of data to use
·special bank switching.
In the architecture of bank, bank 1 (Standard RAM)
is not able to be switch low address
C""X0000H-""X7FFF).

Entry HL:Address to be accessed


C :Bank number
Exit B :Data which be read
Entry HL:Address to be accessed
C :Bank number
Exit B :Data to be written
Entry HL:Start address to be changed
A :Bank number
DE:Start address i~ current bank
BC:Byte length to be read
Exit None
Entry HL:Start address to be written
A :Bank number.
DE:Start address in current bank
BC:Byte length to be written
Exit None

Bank number
Bank *1 (Standard RAM) :"X00
Bank *2 CRAM #2) :""X08
Bank 13 CRAM #3) :"X0C

fSTEM label define >>>


EQU ""X0A1 •, Bank control port
EQU ""X0A0 ,• Bank status port
ORG ""X0000 ,• This program can be located
,• any place
,• This switch should be change
,• according to the situation
EQU -1 • High address C"'X8000-"XFFFF)
'

- 56 -
HOW TO USE 2ND/3RD RAM
-
SLOW EQU 0 ; Low address (AX0000-AX7FFF)
; <<< Byte access routine>>>
BYTER: DI ; Disable interrupt
IN STATUS ; Read current bank status
PUSH PSW ; Save current bank status
IF SHIGH
ANI AB11110011 ; Clear high address of bank
; switch
ORA C ; Set new data of bank
ELSE
PUSH PSW ; Save curre"t bank
MOV A,C : Pick up new bank data
RAR ,•
RAR Shift 2 bit
MOV C,A Restore bank data
POP PSW Pick up current bank
ANI AB11111100 Clear low address of bank
switch
ORA C Set new data or bank
ENDIF
OUT BNKCRL ; Select new bank!
MOV B,M ; Read data from some bank
POP PSW ; Pick up before bank
OUT BNKCRL ; Select before bank
EI ; Enable interrupt
RET ,•
BYTEW: DI ; Disable interrupt
IN STATUS ; Read current bank status
PUSH PSW ; Save current bank status
IF SHIGH
ANI "'811110011 ; Clear high address·o-f bank
; switch
ORA C ; Set new data of bank
ELSE
PUSH PSW ; Save current bank
MCV A,C ; Pick up new bank data
RAR ,•
RAR ; Shift 2 bit
MOV C,A ; Pick up current bank
ANI "'B11111100 ; Clear low address of bank
; switch
ORA C ; Set new data of bank
ENOIF
OUT BNKCRL ; Bank switch!

- 57 -
HOW TO USE 2ND/3RD ~AM

MOV M,8 ; Write data


POP PSW ; Pick up before bank
OUT BNKCRL ; Select before bank
EI ; Enable interrupt
RET ,•
; <<< Block access routine >>>
BLOCKR:- DI ; Disable interrupt
PUSH 8 ; Save length
MOV C,A ; Set up bank number
IN STATUS ; Read current bank status
STA CURBNK ; Save current bank
IF SHIGH
ANI "B11110011 ; Clear high address of bank
; switch
ORA C ; Set new data of bank
ELSE
PUSH PSW ; SAve current bank
MOV A,C ; Pick up new bank data
RAR •
RAR ;' Shift 2 bit
MOV C,A ; Restore bank data
POP PSW ; Pick up current bank
ANI "811111100 ; Clear low address of bank
switch
ORA C ; Set new bank data
ENDIF
POP B ; Pick up length
NEXTR:
LDAX D ; Read data
MOV M,A ; Write data
INX D
INX H ; Next position of data
DCX B ; Decrement counter
JNZ NEXTR ; Loop until dQne
LOA CURBNK ; Set previous bank
OUT BNKCRL ; Select previous bank
EI ; Enable interrupt
RET •
'
BLOCKW: DI ; Disable interrupt
PUSH B ; Save length
MOV C,A ; Set up bank riumber
IN STATUS ; read current bank status
STA CURBNK ? Save current bank
IF SHIGH
ANI "B11110011 ; Clear high address of bank

- 58 -
HOW TO USE :3RD RAM

swit
IRA C ; Set new data of bank
:LSE
'USH PSW ; Save current bank
'OV A,C ; Pick up new bank data
AR •;•
AR Shift 2 bit
,ov C,A ; Restore bank data
'OP PSW ; Pick up current bank
,NI ""B11111100 ; Clear low address of bank
switch
)RA C ; Set new bank ~ata
~NOIF
,op B ; Pick up length
NEXTW:
MOV A,M ; Pick up data
STAX D ; Write data
INX H ,•
INX D ; Next position of data
DCX B ; Decrement counter
JNZ NEXTW ; Loop until done
LOA CURBNK ; Restore previous bank*
OUT BNKCRL ; Select previous bank
RET •
'
: <<< ~stem work area >>>
CURBNK: DB ... X00 ; ~urrent bank data
ENO

- 59 -
CHAPTERS
UNDERSTANDING THE RAM FILE CONCEPT

S.1 ·suMMARY
Usually, the RAM files are controlled by the ROM #0,
settled in ROM socket #0 at the shipment. There are many
rules to·use the RAM file. Unless you replace this ROM #0
with your own ROM, ROM #0 checks the RAM file organization and
pointers in the bookkeeping area sometimes, even if you don't
use BASIC, TEXT or TELCOM. (For instance, at Power on and
·sank• command in menu.) If you ignore the standard rules for
RAM file handling, ROM #0 will flush not only the files which
were made by your own application program ,but also the files
which were made by BASIC and TEXT in ROM #0. In order to save
your files from such kinds of accidents, please read following
chapters about .the RAM file handling and understand the
standard rules in PC-8201A.
The two situations were considered for this section.
Someone wants to handle RAM files with the machine language
subroutine in the BASIC m·ode. In this case, opening the file
will be done by a BASIC command, OPEN. And the file will be
closed and deleted by CLOSE and KILL command in BASIC. So the
machine language subroutine will make up the lacking
facilities in BASIC commands. For instance, Insert a data at
the middle of the opened file. In this case, you had better
care about a few pointers only. You needn't know the
directory structure.
But another person might try to make a his (or her)
original application program without using BASIC. He (or She)
might open a file, save data, append data, insert data, delete
data and erase a file with his ( or her) own application. In
this case, the name of the data file should be registered by
that application program. So that programmer need to.know the
Directory configuration and many parts of the pointers
playing.

~ 60 -
UNDERSTANDING THE RAM FILE CONCEPT

This section is written for supporting both of them.


The programmer who wants to make a original application
without BASIC, needs much more information than a user who
uses BASIC. But too much data. sometimes confuses a novice
programmer who wants to make a subroutine for BASIC main
program. After long consideration, I decided to obey the
famous common saying, •The greater serves for the lesser·.
Therefore I serve everything what I know. Please find what
you want to know in.the following section.
In these chapters, I tried to describe each section
independently. You, ho~ever, might meet unknown words
sometimes. Please refer to another section or another chapter
at that time. I hope you will make many good application
programs with this document.

- 61 -
UNDERSTANDING THE RAM FILE CONCEPT

5.2 WHAT IS RAM FILE?


In PC-8201A, you can have many files in RAM area at a
time ,like files on the floppy disk. The files are classified
into three suffixes:.OO(cument) .; ,BA(sic) and .CO(mmand).
Hereafter .OO(cument) file is abbreviated 00 file, BA(sic)
file is BA file, and .CO(mmand) file is CO file. And
sometimes the word •ASCII file· is used in place of ·oo file·.

5.2.1 DO File <ASCII File)

The 00 file is created by BASIC, TEXT and TELCOM. Of


course, you can load. a 00 file from I/0 in menu mode. In
BASIC, the ·oPEN• command handles the 00 file. The OPEN
command with.FOR OUTPUT• option makes a new 00 file. OPEN
with ·FOR APPEND• opens the 00 file ·in order to add the data
after the last data that has already been entered. When there
is no file whose name is same as the specified in the ·oPEN•
with •FOR APPEND•, that OPEN command works as the OPEN with
FOR OUTPUT. The OPEN with FOR INPUT opens the specified file
to be ready for sequential reading.
The •sAvE• command with •,A• option or •sAvE• command
with the file descriptor followed the suffix, ·.oo· stores a
BASIC· program as a 00 file. This 00 file is~ sometimes,
called as ASCII (saved program) file. ( Note: A SAVE command
without ·,A• option creates a BA file.) In this case, the
BASIC program in the BASIC files area is saved into the 00
files area in the ASCII format. So you can read it in TEXT
mode.c•sAvE• command without •,A• or without the suffix, •.oo•
only registers the file name with the suffix, ·.BA• and
changes some pointers. It does not make a new file. Please
refer to next section about BA files. And I think almost
BASIC interpreter have this •ASCII save function· for the disk
files. Refer to BASIC reference manual if you have another
disk top personal computer's manual. )

- 62 -
UNDERSTANDING THE RAM FILE CONCEPT

I A
I
Upper
I
'' I
I •
I 00 files I •

Lower
non-registered V
·BASIC program
or
9aved BASIC
program
•A.BA•

----------------- <-- TXTTAB

Type BASIC program in BASIC mode.


Do •sAvE• command.
SAVE .TEsr· ,A
or •
SAVE .TEST.oo·

....
:Up,:,er
DO file!!

------------ I
I

TiST.00 : <-- New 00 f i 1e


is inserted
:Lower
non-registered V
BASIC program
or
saved BASIC
program
'A.BA•
----------------- <-- TXTTAB

Fig 5.1 SAVE with ".DO" or·',A" option

- 63 -
UNDERSTANDING THE RAM FILE CONCEPT

There are 2 type of hidden 00 files in PC-8201A. One


is the ·scRAP• file used in TEXT, and another is the •EDIT•
file used in BASIC. The screen oriented text editor in
PC-8201, named TEXT, has wonderful functions called ·ccp·.
The CCP functions mean SELECT, CUT, COPY and PASTE. (The
detail information about these functions are explained in the
PC-8201A user's guide.) The CUT command or COPY command after
SELECT command makes a temporary DO file. This DO files can
be invoked by PASTE key many times. Though this file cannot
be found in menu level, this file wi 11 be kept unti 1 n'ext
SELECT-COPY or SELECT-CUT will be executed and is not broken
by the PASTE key.
And more good feature is in this DO file. Since the
contents of this DO file is treated as the data from keyboard,
this file can be used in BASIC. After saving a part of a file
in SCRAP with SELECT-COPY function, return to Menu, and invoke
BASIC. The contents of this •scRAP• file will appear by
.PAST• key. Cin the PC-8201A user's guide, this temporary 00
file is called •PASTE buffer·.)

Another one, •EDIT• file, is created by EDIT command


in BASIC. The EDIT command in BASIC falls into the TEXT
editor with the BASIC file. At that time, the BASIC program
is translated in to ASCII format file, .EDIT•, and original
BASIC file is killed. This file is erased when the EDIT mode
is finished by double ESC or F.S, converted into BASIC file
and saved. So no one can find this file at the menu level.

The DO file usually consist of the •ASCII• characters.


And you cannot use the 3 Control Characters, NULL (0),
Control-Z (26) and Back Space (127>. C The ·controt-z• is
sometimes abbreviated as •Az·.>
The Control-Z is used as the
End of DO file. So if you store it as a one of the data in
the middle of the DO file, the standard programs, BASIC, TEXT
and TELCOM ,will regard that Control-Z as the End of that 00
file. The data after that Control-Z will be lost. Otherwise
the NULL is used to fill the hole dug by MAKHOL. After
copying or inserting the data in to the hole, some routines
tries to find the end of the data by finding the NULL. T~en a
routine squeezes the NULLs. Therefore the NULL in the middle
of the DO file might cause the serious problems. similarly,
the Back Space has special meaning in DO file. Please don't
use there three Control characters in the DO file. BASIC's
PRINT* command cannot save these control characters in to the
DO file.
NOTE: MAKHOL and MASOEL are name of the routine

- 64 -
UNDERSTANDING THE RAM FILE CONCEPT
• 4

stored in ROM i0. Refer to 'Useful Routines for RAM


file han~ling in ROM i0'.

ex. When DO file is made. in PC-8201A


1. TEXT always creates and modifie9 DO files.
2. SAVE command with ',A• creates a DO file in BASIC.
3. UPLOAD and DOWN LOAD sends or receives a DO file
through RS-232C in TELCOM.
4. DO file can be saved or loaded from CASSETTE and
RS-232C in MENU.
5. OPEN with 'FOR OUTPUT' registers the file name and
insert only End of file character as the 00 file
in BASIC.

- 65 -
r

UNDERSTANDING THE RAM FILE CONCEPT

5.2.2 BA File
The BA file is made in BASIC mode or made by LOAD
function in Menu mode·. There are two types of BA file in
PC-8201A. One-is a ·saved· BASIQ program, and another is
·non-registered· BASIC program. Sometimes the
·non-registered· is called the ·un-saved· BASIC program,
because ·un-saved· will make sense more than ·non-registered·
for a person who knows BASIC very well. The BASIC program
typed just after selecting BASIC mode in menu level, is called
·non-registered· "BASIC file, since the name of the program has
not been registered in the directory area yet. But after
executing ·sAvE· command in BASIC mode, that ·non-registered·
BASIC program becomes a ·saved· BASIC program. (In the point
of view, "SAVE• command in BASIC, the word ·un-saved". and
·saved" are suitable, I think.) The ·sAVE" command in BASIC
·register·s the file name and the starting address in the
directory area. Then the file name can be seen on the display
screen of the MENU or by •Files· command in the BASIC mode.
Meanwhile the ·LoAo• function in MENU can create a
"saved• BA file directly. The "LOAD• function can read a
BASIC program from the cassette, and can ·register" its name
in the directory area. So after "LOAO"ing in Menu, the
program name appears on the Menu screen.
ex. The flow diagram of making BASIC program
1. Select BASIC in menu level
2. Type BASIC program ·
10 PRINT •HELLO•
20 ENO
3. In this point, this BASIC program is called
·non-registered· program.

4. If you return to menu level now, this program is


reserved. You cannot find this program in Menu
mode in this time. Next time you select BASIC in
menu mode, LIST command shows you this program
agaiM. This program will be kept unless you do
NEW command, LOAD ASCI.I saved file in RAM or LOAD.
a file through I/0, cassette and RS-232C.
5. Do "SAVE• command.
SAVE ·rEsr·
or

- 66 -
UNDERSTANDING THE RAM FILE CONCEPT

SAVE .TEST.BA •.

< SAVE ·TEST.oo·


or
SAVE "TEST.,A has another meaning.)

6. Then ·non-registered" program becomes a


"registered· program. This program is called "BA"
file simply. And there is nothing in the
non-registered program area.

Just after doing SAVE, you can list the program with
LIST command. So you might be confused. But don't worry
about it. The following illustration will help you to
understand not only why LIST command just after SAVE command,
can list the "saved" program, but also why PC-8201A can have
many BASIC programs at a time, I hope.

- 67 -
UNDERSTANDING THE RAM FIL€ CONCEPT

1. You are in MENU mode

"'XFFFF
-----------------
I
I

l 00 files
----------------- "'XUUUU
I I
I I

: saved BA file :
<- BOTTOM
C"'XF980)

Fig 5.2
2. Select BASIC in MENU and TYPE a BASIC program.
LIST shows you the non-registered BASIC program.

"'XFFFF
-----------------
: 00 files

---------------I AXYYYY
I

non-reg i!,tered:
BASIC program l
----------------- <-- ("XUUUU)
TXTTAB
saved BA
file

-----------------<--BOTTOM
Fig S.3

- 68 -
UNDERSTANDING THE RAM FILE CONCEPT

3. Return to menu by MENU command

"'XFFFF
-----------------
00 files
----------------- "'XYYYY
non-registered:
BASIC program:
----------------- "'XUUUU
I I
I I

: Saved BA file:
-----------------<--BOTTOM
Fig 5.4

4. Select BASIC again. LIST command lists the


non-registered BASIC program which you typed in (2).

"'XFFFF
--------- ------
-------
I
I

: DO files
---~-------------
I I
AXYYYY
.1 I

non-registered:
program
----------------- <- TXTTAB
C"XUUUU>
: Saved BA files:
-----------------<--BOTTOM
Fig S.S

69 :-
UNDERSTANDING THE RAM FILE CONCEPT

S. · SAVE •TEST•. TXTTAB sti 11 points the pragram typed in <2>.


So the same list appears on the screen by LIST •

..
""XFFFF
-----------------
DO files
----------------- ""XYYYY
TEST.BA

----------------- <- TXTTAB


(AXUUUU)
Saved BA
files

----------------- AX8000
_Fig 5.6

- 70 -
UNDERSTANDING THE RAM FILE CONCEPT

6. MENU and s·elect BASIC again or-· execute NEW commandin BASIC.
Now, LIST command lists nothing. Type new BASIC program,
again. LIST lists the pr-ogr-am that you typed just now •

I
• I ... XFFFF

-----------------
: 00 files

----------------- . . xzzzz
non-r-eg i ster-ed: .
pr-ogr-am ar-ea:

----------------- <- TXTTAB


C... XYYYY)
l TEST.BA

----------------- . . xuuuu
I
I

: Saved BA files:
-----------------<--BOTTOM
Fig 5.7

- -----71 -
UNDERSTANDING THE RAM FILE CONCEPT

7. •
LOAD •TEST.BA• in this case, or select •TEST.BA• directly in
MENU. LIST shows you the program, TEST.BA.

"'XFFFF
=================

: 00 files

----------------- "'XZZZZ
non-registered:
program

---------------
I
"'XYYYY
I

: TEST.BA
----------------- <- TXTTAB
C"'XUUUU)
: saved BA files:
-----------------<--BOTTOM
Figs.a

- 72 -
I
UNDERSTANDING THE RAM FILE CONCEPT

BASIC interpreter regardes that the current TXTTAB


indicates the current BA file. So LIST command lists the
program which was saved just now because of specified by
TXTTAB.

The BA file can be created in BASIC mode and can be


LOADed in BASIC mode and MENU mode. Refer to the PC-8201A
user's guide and reference manual. And BA file is executed
with BASIC interpreter at the menu level by selecting the BA
file directly, as you know. In other words, when you select
the BA file name appeared on the MENU, PC-8201A invokes the
BASIC interpreter, LOAD that BA file and RUN it automatically.

- 73 -
UNDERSTANDING THE RAM FILE CONCEPT

S.2.3 CO File
The CO file is made in BASIC with BSAVE command or can
be loaded and saved from the cassette tape in MENU mode. The
CO file is, sometimes, called ·machine language· file. It can
be executed directly like a command in menu level,when
·Execute· address was specified in BSAVE and the start address
is higher than the second parameter in the latest ·cLEAR•
command in BASIC. The default value is AXF380. So no CO file
can be executed directly from the menu level without CLEAR
command. The CO files are located above the DO files.

- 74 ~
UNDERSTANDING THE RAM FILE CONCEPT
.
5.2.4 The Order Of The Files In RAM
The order of these files in PC-8201A is fixed.

----------------- ~XFFFF

=================
CO file9

00 files

------------~----I
I

non-registered:
BASIC program :

: BA file9
----------------<-BOTTOM
Fig 5.9 the order of the files in RAM

Of course, the size of each file is dynamic.

- 75 -
.

CHAPTER 6
DIRECTORY STRUCTURE

6.1 DIRECTORY CONFIGURATION PER ENTRY

The directory area is allocated in th~ middle of the


bookkeeping area. The top of the address is F84F in
hexadecimal. The directory configuration is shown below.
OIRTBL: BASIC
FILER
<--------- AXF84F
TELCOM
NULOIR: (Directory for non-r-egister-ed pr-ogram)
SCRDER: (Directory for- SCRAP)
EDTOIR: (Oirector-y for- EDIT command)
USRDIR: <Director-y for- user--defined files)
••
(( End-of-directory)) AXFF
r-f. The non-r-egistered progr-am means non-saved BASIC
. program. Refer- to ·eA file· in the pr-evious section.
•Directory for- SCRAP• and ·oirectory for- EDIT command•
ar-e explained in ·oo·file·.

Each slot in the directory consists of 11 bytes, 1


byte flag, 2 bytes address and 8 bytes file name. The first 6
slots in directory ar-ea ar-e initialized by INIT routine at the
COLO START.

- 76 -
DIRECTORY STRUCTURE

Oirf slot's configuration per entry

Dir-Y f 1 ag (1 byte)
Adcfiel d (2 bytes)
Fi 1e (8;bytes)
· Tota 1 11 bytes.

Bi~gnment of Directory flag

Bi-Master bit (1 when directory valid)


Bi ASCII bit (1 when ASCII-text file)
Bi Binary bit (1 when Machine-language file)
Bi File-in-ROM ( 1 when file is in ROM)
Bi' Hidden fi 1e (1 when file is hidden)
Bi
Bf RAM file open flag
Sj for internal use (always set to 0 normally)

VPf address-field

B, e - Address which TXTTAB must be set to


oe - Beginning address of file
c,e - ditto

,XTTAB in BASIC shows the lowest byte of the file,


the fir~ink pointer in the BASIC program file. Please
refer to her manual to understand what 'link pointer' is,
if you wco handle the BASIC programs.
:nitialized values for first 6 slots in Directory
are shooelow. The first 3 files are stored in ROM and
displaye,the menu screen. (These 3 files are called the
'standar~ograms".) Next 3 files are used for hidden files
created AM area. These hidden files will not appear on
the Menueen. Refer to previous section, 'DO file' and 'BA
file'. characteristics· of these hidden files are
describeiere.

- 77 -
DIRECTORY STRUCTURE
•• ·-1

rf. First 6 slots in Directory (Initialized data


stored in AX6C8E)
08 AB1011000
DI.J Start address
, of a=p.sic
DB 'BASIC
DB 0
DB AB101-10000
01.J Start address
, of TEXT
08 'TEXT
DB 0
OB ""B10110000
01.J Start address of TELCOM
OB 'TELCOM'
DB 0
;for non-registered program
DB "'B10001000
DI.J 0

DB 0
DB 'XXXXXXX'
;for SCRAP file
OB ""B11001000
DI.J 0
08 0
DB 'YYYYYYY'
;for EDIT command of BASIC
DB AB01001000
DI.J 0
OB 0
DC 'ZZZZZZZ'

78 -
~PTER 7
~GANIZATION

~ FILES

~pter 2 to understand the whole of the

I are stored with the fixed order. It


.Jes, the BASIC programs which has the
j at the bottom of the RAM area, near
~II files, the suffix is ".00") are
files. And CO files, the Machine
,CO" are saved above the DO files, near
(llustration will help you understand

-~

- 79 -
RAM ORGANIZATION

1. There are S files in RAM.

AXFFFF ~---------------
:Bookkeeping I
I
""
I
Area I

----------------
-----------------
:Free area & I
I

:Data area lUpper

MACHIN.CO

,.
I

DIARY.DO

I
I

MEMO.DO :Lower

GRAPH.BA
V

GAME.BA I
I

: <- BOTTOM

Fig 7.1.

- 80 -
RAM ORGANIZATION

2. Add new BASIC file, GOLF.

• --

----------------- <---
A I
I MACHIN.CO
Moved
Upper
----------------- up

I
I DIARY.DO

-----------------
I
I MEMO.DO

----------------
I
I
<---
I
I GOLF.BA :<-- Added here

---------------- <---·
Lower I
I GRAPH.BA
Not
I
I

V
-----------------
I
I
Changed
I
.I
I
I GAME.BA

----------------- <---
Fig 7.2

- 81 -
RAM ORGANIZATION

3. Add new ASCII file, ADORES.


--~

,.
----------------- <--
I
I

Upper- l MACHIN.CO I
.'

----------------- Moved
up
: DIARY.DO
,.I
I
I

: MEMO.DO
<--
: ADORES.DO <-- Inserted
here
<---
Lower- GOLF.BA
-------------- Not
V changed
GRAPH.BA

: GAME.BA
-----------------<----
Fig 7.3

-·82 -
RAM ORGANIZATION
-4

Add new CO file, CHAR.CO

... : CHAR.CO l<-- Inserted here

----------------- <---
Upper : MACHIN.CO

: DIARY.DO

l MEMO.DO

Not changed
: ADORES.DO

I
I

Lower : GOLF.BA

V
: GRAPH.BA

l GAME.BA

----------------<----
Fig 7.4

A new BA file is created above the old BA files.


Otherwise a new DO file is stored below the lowest DO file,
just above the BA files. A new CO file is made just ABOVE the
CO files. (Just below the address which is pointed by VARTAB.
Refer to "Bookkeeping area".)

- 83 -
RAM ORGANIZATION

And you know that the non-registered BA file is


created between the BA files and DO files, as described in "BA
file" of "What is RAM files·.

ex.
Non-registered program is created just
under the ASCII file.

I A
I

: ASCII1.DO
Upper
I
I

non-registered:
program

----------------- Lower
: BASIC2.BA V

Fig 7.5 Position of non-registered program

- 84 -
RAM ORGANIZATION

The detail information· about the directory


configuration is described in ·Directory structure· • The
bookkeeping area and the directory area are situated at the
top of RAM area.

"'XFFFF ----------------- <---.

"'XF977 I
I
I I I
I I I

: Directory area: bookkeeping


I
I area
"'XF84F

"'XF380 ----------------- <---

Fig 7.6 Directory position

- 85 -
RAM ORGANIZATION

7.2 BOOKKEEPING AREA

The book-keeping area is lQcated at the top of the RAM


area. The area is divided into 3 parts. The first part,
lowest part from AXF380 to AXFBBF, includes the pointers and
flags for RAM file handling. And many BASIC interpreter's
flags, pointers and temporary data area are here. As you
know, the directory area is included in this part.
The second part, AXFBC0 to AXFE3F, is used for the
line buffer. of LCD display. BASIC uses this area in the
Screen Editor function, also. But the concept of this line
buffer is different from the VRAM in the traditional disk top
personal computer. Only the character- codes are stored in
this buffer. There is no attribute data. The attribute data
is stored in another table. Refer to the chapter 9,
explanation about the LCD driver.
The third part, AXFE40 to AXFFFF, is reserved by BIOS.
The switches and data storage for RS-232C, Key Board and other
I/0 drivers are stored here.

AXFFFF ----------------
'I
: Part III BIOS's data

AXFE40 ----------------
,'
l Part II LCD buffer

AXFBC0 -----------------
I' : BASIC's data
: Part I :. File handling data
Directory
AXF380 -----------------
Fig 7.7 Bookkeeping area

-~-
RAM ORGANIZATION

7.2.1 Part I ( For RAM File Handl1ng And BASIC>

NOTE: ..
In this section, the articles about the
pointers and flags for BASIC are omitted, because this
document is written for the programmer who wants to
understand the many good features in PC-8201A, in
order to utilize this machine with 2nd ROM or user's
machine language program. Not written for the people
who wants to understand the internal specification of
PC-8201A's BASIC interpreter. So I think this
document is unfriendly for such kind of people.
Please refer to another manuals and textbook if you
need understand the BASIC interpreter.

There are many important pointers are stored in this


area for RAM file handling. When some of them are mis-handled
in your routine, all RAM files might be deleted at next
operation of the standard ROM,ROM #0, for instance, power-on
or next SAVE command in BASIC. Because the standard programs
(BASIC, TEXT and TELCOM) and operating system (represented by
Menu), believe that these pointers point the right address.
So if a pointer which should point the lowest address of the
DO files, points one byte smaller than it should point
correctly, TEXT might not invoke any DO files in it. Please
understand the purpose of each pointer and make sure that each
pointer has a right value any time.

The important pointers for RAM files are listed below.


ADDRESS <Hex> NAME SIZE (Decimal)
F380 FSIOSV 2
F384 HIMEM 2
F459 STKTOP 2
F450 TXTTAB 2
F84F DIRTBL 33
F870 NULDIR 11
F87B SCROIR 11
F886 EOTOIR 11
F891 USROIR 231
F9B0 BOTTOM 2
FA9A MEMSIZ 2
FABF FRETOP 2
FAE1 ASCTAB 2

- 87 -
RAM ORGANIZATION

FAE3 8INTAB 2
.FAES VARTAB 2
FAE7 ARYTAB 2
FAE9 STREND 2
FB63 FILTAB 2
FB67 NULBUF 2

7.2.1.1 FSIDSV

ADDRESS "'XF380
SIZE 2 bytes
Purpose First power on or not
If this FSIDSV is not identical' with FRSTID
("'X8A4D), the initialization routine falls into the
·coLD START• routine. In this case, the all data and
files in PC-8201A are cleared. The ·coLD START•
routine sets FRSTID here after done the
initialization. And no one may not change this ID
value.

7.2.1.2 HIMEM

ADDRESS "'XF384
SIZE 2 Byte

PURPOSE Highest memory available memory

This pointer keeps the highest memory address


available for BASIC. The area between the address in
this pointer and "'XF380 is reserved for the machine
language file or another user's special working area.
No standard program will break the data in this area
except POKE statement in BASIC. (The •poKE• statement
can write on anywhere in the RAM which is selected
now. So be careful with the address in POKE statement

- 88 -
RAM ORGANIZATION

when you use it for s~ori~g your machine language


program or character data into RAM area.) The "HIMEM"
can be changed by the second parameter of "CLEAR"
statement in BASIC. Refer to the PC-8201A BASIC
reference manual.

7.2.1.3 TXTTAB

ADDRESS AXF450
SIZE 2 bytes
PURPOSE Pointer to beginning of current
BA file
This pointer is valid in BASIC mode. In
another mode, TEXT or TELCOM mode, this pointer keeps
the latest value used in BASIC. In BASIC mode, the
• address of the first link pointer is stored here. And
this value won't be changed in BASIC mode unless
"LOAD" command is executed to load another BASIC
program, or "NEU" command. Almost internal routine
for BASIC interpreter refers to this pointer to know
the top of the current program. And this pointer 1s
very important when a BA file is deleted, too. You
cannot kill a BA file in BASIC mode when this TXTTAB
points the BA file. Refer to "How to delete a BA
file".

7.2.1.4 STKTOP

ADDRESS AXF459
SIZE 2 bytes
PURPOSE Top location to use for the stack
Initially set up by INIT routine in ROM #0
according to memory size to allow for 256 bytes of
string space. This value will be changed by a CLEAR
command with the first argument. The difference
between MEMSIZ and STKTOP means total string space.

- 89 -

,,-
.
RAM ORGANIZATION

The 2 byte space between MEMSIZ and FILTAB is kept for


·vAL• function in BASIC. The ·vAL• function sets ·0·
at the end of the strings on evaluating the strings.
So this 2 bytes area prevent to over-write the FCB
area above the FILTAB.

7.2.1.5 OIRTBL

ADDRESS "XF84F
SIZE 33 bytes
PURPOSE directory for program in ROM
The names and pointers for the programs 1n ROM
are stored here. They are BASIC, TEXT and TELCOM. If
you don't want to use these standard programs, you can
use this area for your programs. This area will be
kept until •coLO START• is invoked. Refer to
·oirectory construction.·

7.2.1.6 NULOIR

ADDRESS . "XF870
SIZE 11 bytes
PURPOSE Directory for non-registered program
This area is kept for internal use. The
"non-registered program· that means the BASIC program,
just typed after selecting BASIC, uses this area for
pointing the starting address. There is a detail
explanation about the 'non-registered· program in the
previous section, 'BA file". And also, refer to
"Directory Construction".

- 90 -
RAM ORGANIZATION

7.2.1.7 SCRDIR •

ADDRESS "'XF87B
SIZE 11 bytes
PURPOSE Directory for SCRAP
The TEXT editor can do •sELECT•, •cur·, •copy•
and •pAsr•. This directory is used for this
·temporary file•, SCRAP, in TEXT. This file is
created when some characters are ·sELECT.ed and
•coPY.ed or •cur·. (Refer to PC-8201A user's guide
•sELECT•, •cur•, ·copy• and •PAST •• ) This file is kept
even if you exit from TEXT. And you can use it in
another programs, BASIC, TELCOM and so on. If you CUT
or COPY without SELECT, the starting address points
Control-Z. It means that the SCRAP files is empty.
Refer to •Do file• and •Directory Construction".

7.2.1.8 EDTOIR

ADDRESS "'XF886
S-IZE -11 byte!!
PURPOSE Directory for EDIT in BASIC
The EDIT command in BASIC makes a temporary DO
file. This slot is used for this file. Refer to •no
file· and ·Directory Construction·.

7.2.1.9 USRDIR

ADDRESS "XF891
SIZE 231 bytes
PURPOSE Directory for user's files (21 slots)
This area is used for BA files, DO files and
CO files which user makes. 21 files can be registered

- 91 -

/
RAM ORGANIZATION

here at most. The end of directory area is indicated
by ·--xFF·, ·Directory search stopper·. Refer to·
Directory Construction·.

7.2.1.10 BOTTOM

ADDRESS "'XF9B0
SIZE 2 bytes
PURPOSE Bottom address of RAM
The lowest available RAM address is saved
here. You can know how many RAM chips are installed
in this RAM bank easily by checking this pointer.

7.2.1.11 MEMSIZ

ADDRESS "'XFA9A
SIZE 2 bytes

PURPOSE Highest location in Memory


This pointer points the top ~f the string
space. The area between the MEMSIZ and FRETOP+l is
ca 11 ed ·used string space·, and the area between the
FRETOP and STKTOP +1 is ·Free string space·.

7.2.1.12 FRETOP

ADORESS "'XFABF
SIZE 2 bytes
PURPOSE Top of the string free space
The highest address (closer to ... XFFFF) of the

- 92 -
- I

RAM ORGANIZATION

string free area is kept in thi9 pointer. The lowest


address is kept by STKTOP + 1.

7.2.1.13 ASCTAB

ADDRESS ... XFAE1


SIZE 2 bytes
PURPOSE Pointer to start of ASCII files
This pointer points the first byte of the
first 00 <ASCII> file.

7.2.1.14 BINTAB

ADDRESS ... XFAE3


SIZE 2 byte9
PURPOSE Pointer to 9tart of COMMAND file
The lowest address of the first CO file is
kept here.

7.2.1.15 VARTAB

ADDRESS ... XFAES


SIZE 2 bytes
PURPOSE Pointer to simple variable space.
This pointer keeps the start address of
VARIABLE TABLE area just above the CO files.

- 93 -
RAM QR{;ANIZATION

7.2.1.16 ARYTA8

ADDRESS "XFAE7
SIZE 2 bytee

PURPOSE Pointer to beginning of array table


The ARRAY TABLE is allocated just above the
VARIABLE TABLE. This points the beginning address of
this ARRAY TABLE.

7.2.1;17 STREND

ADDRESS "XFAE9
SIZE 2 bytee
PURPOSE End of storage in use
This pointer keepe just above the address of
ARRAY .TABLE. The area between this pointer and the
stack pointer can be used as the FREE area.

Note:
When you ~ill use this FREE area, you have to consider
about the stack area. As the stack pointer points the
current bottom of the stack area, you had better about
120 bytes for the feature etack operation.

7.2.1.18 FILTAB

ADDRESS "XFB63
SIZE 2 bytes
PURPOSE Point to address of file data
This points to the starting address of the

- 94 -

/
RAM ORGANIZATION

file data area. 1


The file data area consists of the
1
FCB address. If MAXFILES command in BASIC was not
executed after 'COLO START", this table has 4 bytes.
The first 2 bytes points the NULL files buffer.
CNULBUF points the same address.) The second 2 bytes
points the #1 file's FCB address. Refer to the
following section about FCB.

7.2.1.19 NULBUF

ADDRESS AXFB67
SIZE 2 bytes
PURPOSE Points to address of file #0 buffer
The buffer for file #0 , sometimes called
NULBUF, is allocated just above the file data table,
pointed by FILTAB.

- 95 -
RAM ORGANIZATION

AXFFFF ----------------- I
I

Bookkeeping I
I

: <--- AXF380
----------------- -
User's machine
area
or
Device code
<-- HIMEM

FCB l·
I
C#1 -- #n) I

: <-:-- Address is
stored in FILTAB
Nul buffer
<Fi 1e #0 > I
I

: <-- NULBUF
I
I

: FCB address I
I

: <-- FILTAB
( 2 Bytes)
---------------
Used : <-- MEMSIZ
String area

---~-----------
Free : <-- FRETOP
String area
I
• I

I
I : <-- STKTOP
: Stack area I
I
I
I :<- Stack Pointer
I
I

Free area I
I

: <-- STRENO
I
I

: Array data
: <-- ARYTAB

- 96

/
.I
I

: Simple I
I

l Variables I
I
·,
I l <-- VARTAB.
-----------------
: CO fi 1es I
I

l <-- BINTAB
,-----------------
l DO fi 1es I
I

l <-- ASCTAB
I
I

BA files I
I

.I
l<--
I
TXTTAB
I
'
:<-- BOTTOM

tig 7.8 Pointers and ROM configuration

- 97 -
RAM ORGANIZATION

7.2.2 Part II < VRAM Area For LCD)


ADDRESS
SIZE 640 by~es
PURPOSE VRAM
This area is used for the VRAM of LCD (liquid
Quristal Display). In this area, the data is stored
as the character code. C ANSI character code. Refer
to •APPENDIX A4• in PC-8201A Reference Manual.> The
LCD driver, installed just below the LCD panel, gets
this character code and displays it on the LCD. The
320 characters C 40 by 8) can be shown on the LCD
panel at a time. So only second 320 bytes, from
AXFD00 to AXFE3F, are used for VRAM. The first 320
bytes, from AXFBD0 to AXFCFF, are used only when TERM
mode is selected in TELCOM. (You can find •PREv• at
the bottom of the screen in TERM mode. The ·PREV•
shows you the previous screen in TERM mode. Refer to
·chapter 8 TELCOM• in PC-8201 User's Guide. The
• •PREVIOUS• is the first TERM SUBCOMMANDS.>
The data in VRAM appears when LCD· driver is
turned on. Refer to Chapter 9 about the control
sequence for LCD management.·

7.2.3 Part III ( Bookkeeping Area For BIOS)

ADDRESS

This area includes the data area for RS-232C


driver, the buffers relevant to Key Board driver and
working area for LCD driver. Refer to Chapter 9 - 15
to know how to use the peripheral drivers and the data
in this area.

- 98 -
RAM ORGANIZATION

7.2.4 FQ Control Block)

YJ the FILTAB points the lowest address of the


file con~ata area. It doe~ NOT mean FCB. The FILTAB
points tht of the starting address of the FCBs, FCB
Offset, ifile is opened.

e~B and FCB

Dnory (in hexadecimal)


F: 6E F1 77 F2 •• •• •• ••
Tht 2 bytes (AXF16E) points the starting address
o1 FCB of #0 file (NULL buffer). The second 2
b)'XF277) is the top address of the FCB for the
fi. These starting addresses are called FCBOFF
CFset address).
T~area for NUL and file #1 are allocated by the
INITIALIZ~ine in ROM #0. The 2nd and more FCB area will
be allocatthe BASIC language, MAXFILES command. Refer
to PC-820»rence manual.

The FCB ca of 9 ~ytes parameter area and 256 bytes


buffer ancept for NULBUF. NULBUF consists of only 256
bytes bufna. The purpose and the size of the parameters
ar• listew. Since this FCB can support the Floppy Disk
file, you =ind some meaningless parameters for RAM files.
Of cause, 1n use them for own your purpose if you wish.

(1) FL.MOO

Address: FCBOFF+0
Size: 1 byte

The file mode of the FCB. If this byte is not


se~is FCB is not used in BASIC. If you obey the
BA.rule, you have to set non zero value here when
yo~ that fi 1 e.
1 INPUT on 1 y
2 OUTPUT only
8 APPEND only

- 99 -
RAM ORGANIZATION

(2) FL.FCA
ADDRESS: FCSOFF + 1
SIZE: 1 byte
The· first cluster allocated to file. In RAM file
handling, this parameter has no meaning.

C3) FL.LCA
ADDRESS: FCBOFF + 2
SIZE: 1 byte
The last cluster accessed. For RAM file open, this
and next byte is used for the storage of the Directory
address of·that RAM file.

<4> FL.LSA
ADDRESS FCBOFF + 3
SIZE 1 byte
The last sector accessed. For RAM file open, this and
previous byte is used for the storage of the Directory
address of that RAM file.

CS) FL.OSK
ADDRESS: FCBOFF + 4
SIZE 1 byte
Disk* of the file or Device IO. The table listed
below is the Device IO table in PC-8201A.
Device name IO number
LCD ""XFF
C CRT ""XFE )
CAS ""XFD
COM ""XFC
< WANO ""XFB )
LPT ""XFA
RAM ""XF9
CRT and WANO is option I/0.

C6> FL.SLB

- 100 -
RAM ORGANIZATION

ADDRESS: FCBOFF + 5
SIZE: 1 byte
Size of last buffer read.
-.
(7) FL.BPS

ADDRESS: FCBOFF + 6
SIZE: 1 byte
The position in buffer for both PRINT and INPUT with
the file One of the most important parameter in
FCB. *·
(8) FL.FLG

ADDRESS: FCBOFF + 7
SIZE
This byte and next byte are used for the offset
address of the RAM file which is opened now. For
example, in the •INPUT• mode file, this offset address
is advanced by 256 bytes when the block-read command
reads 256 bytes from the file into the buffer in FCB.
So in reading or writing to the RAM file (00 file),
the starting address and this offset show the next
byte should be read or written.

(9) FL.OPS

ADDRESS: FCBOFF + 8
SIZE: 1 byte
High byte of the offset address for RAM file. Refer
to FL.FLG.

C10>FL.BUF
ADDRESS: FCBOFF + 9
S~ZE: 256 bytes
Buffer for the file.

- 101 -
CHAPTER 8
RAM FILE HANDLING

In this chapter, the technic to manage the RAM file is


described. The main purpose is to create or delete a RAM file
for the applications stored RAM area or 2nd ROM. As described
before, if there is some violation in standard rules of RAM
file handling, the file you made (or sometimes all files in
the RAM) will be lost by the standard manipulation. (The
·standard manipulation· means the file handling or operation
with Menu, BASIC, TEXT or TELCOM in the ROM #0.)
There are many useful routines to make up these
violation in standard rules in ROM #0. But using ROM #0 from
ROM #1 will reduce the speed of the application. If you want
to handle the RAM file without ROM #0, please make sure 'What
1 1
you should do• in this chapter. And refer to Bookkeeping
and ·oirectory structure·.

NOTE: The another technical manual for PC-8201A has


been available already. There are many information
about the RAM file handling routines in ROM #0 in it.
For example, •oPEN RAM FILES", 'KILL ASCII FILE",
1
'READ A CHARACTER FROM A RAM FILE and 'CLOSE ALL
FILES•. If you will use your application or
subroutine with ROM #0, you had better refer to that
manual.

- 102 -
RAM FILE HANDLING

8.1 WHAT SHOULD WE DO IN RAM FILE HANDLING


In the ·Directory structure· and ·Bookkeeping area",
many rules about the RAM file handling are described. I do
explain again about the important r~les.

1. Make sure that there is enough free area


When a new file is opened, or new data is appended
and inserted, please investigate whether there is enough
free bytes in the current RAM bank. Especially, the free
area requested in OPEN is sometimes ignored. At least, one
byte is necessary for OPEN a DO file. 3 bytes for CO file.
Refer to 'What is RAM file· and following sections.
You can find where the free space is in the figure in
·Bookkeeping are·. The difference between the pointer
•sTREND• and the value in the stack pointer indicates the
free size. But don't forget that some area will be used for
the stack operation in that free area. For instance, the
make-room routine used in BASIC and TEXT recognizes that the
current free space is less 120 bytes than that difference.
In other words, 120 bytes is always maintained for the 60
stack area when new data is stored. Refer to ·MAKHOL• 1n
. ·useful Routine For RAM File Handling In ROM #0·.

2. ·Register file name correctly


The contents of the directory is described in
·oirectory construction·. No one forgets to register the
file name in it. But someone forgets to set up the
directory flag byte and the starting address of the file.
If you don't set the directory flag, the file might be
deleted by Menu or another operation. If you write a bad
starting address in the address field, the link of the
directory and the files will be lost. By the result, you
cannot select a file properly in the Menu mode or PC-8201A
is hung up. Any way, the directory flag and address field
have very important meaning. Please refer to the •Directory
construction· and following sections.

3. Maintain the order of the files

In order to maintain the order of the file, we have to


do a special trick in setting the starting address of the

- 103 -
RAM FILE HANDLING

new file. For a new DO file~ we-have to set ASCTAB -1 as


the starting address of that new file at the directory area.
And for a new BA file, you have to register the ASCTAB -1 in
the ·non-registered· file's directory area and insert double
NULL code there. That new BA file will be created at ASCTAB
-1 and will have the starting address, ASCTAB - 2. In
making both of a new DO file and a new BA file, LNKFIL
should be executed before end of its process •. Refer to
·useful Routines for RAM file handling in ROM 10• to
understand what is LNKFIL.

4. Make and shrink a hole safely

The calculation of the free space is very important.


And you have to maintain the stack area when you make a your
room. And one more important thing is the management of the
pointers. Tne reason why many programs, Menu, BASIC, TEXT
and so on, can use the same RAM area safely is that they
adjust the pointers for RAM every time when they change the
RAM configuration. For example~ BASIC deletes ~ BASIC
program file, he changes many pointers, STRENO, ARYTAB,
VARTAB, BINTAB and ASCTAB. And he turns off the directory
flag in order to indicate that the slot in the directory is
not used now. Refer to MAKNOL and MASOEL in ·useful·
Routines for RAM file handling in ROM 10.·

S. Insert the promissory byte in the file


When you open a DO file, you have to enter one byte
data at least. The data is Control-Z C~X1A), it shows the
end of file in RAM. Some~imes this promissory byte is
forgotten. So the routine which makes up the starting
address in the directory area is confused. Simultaneously
BASIC needs 2 NULL bytes at the end of the file. Otherwise
CO file requires the 6 bytes file header at the top of the
file. Refer to ·what is RAM file·.

6. Make up the starting address in the directory


When you changes the RAM configuration, you have to
care not only the pointers but also the starting address ~n
the directory area. It is easy to image that the starting
address in the address field of all the 00 files should be

- 104 -
RAM FILE HANDLING
.
changed when you make a new BASIC file. (BASIC file 1s
created under the lowest DO file. Refer to "Memory Map
about RAM files" ) And when some data are inserted in
"A.DO", a DO file, the starting address of the DO file and
CO file located above "A.DO" should be changed. Refer to
"LNKFIL" in the "Useful Routines For RAM file Handfing in
ROM #0". You can get the know-how to make up- the starting
address in the directory area. ·

7. Bad data in 00 file


You cannot store the data which include the character
whose code is 0, Axe and AX1A. The ·0· is used "NULL" to
indicate the hole which is not used. Or double NULL means
the end of the BA file. The ·Axe· is used "Back space".
The "A1A" is regarded as the end of the 00 file, as you
know. Refer to "DO file".

- 105 -
RAM FILE HANDLING

8.2 HOU TO MAKE NEU FILE


8.2.1 How To Register The New File Name

At the first, the new file name should be registered


in the user's directory area when you create a new file. The
user's·directory area is started from USRDIR. And the next
byte of the user's directory area, the end of the directory
area, has AXFF ( 255 in decimal). This byte is called
•Directory Stopper·. The used slot starts with the number
larger than AX80 as the directory flag. Therefore it is easy
to find the free slot. Refer to the sample program shown
later.
You had better compare the new file name with the file
name which is existed already. Two files which have same file
name sometimes occur a serious problem. So during searching
the free slot, the existed file name should.be checked. And
if there is a same file name, you had better delete it before
making new file or abandon to make a new file. ·
If you succeed to find a free slot in the user's
directory area, you have to register the directory flag, the
address of the file and the file name. In this time, you have
already known the file name. And you can set the directory
flag now. (You can get the detail information about the
Directory flag in the section, DIRECTORY STRUCTURE.> The
address of the file will be fixed later. Because the way to
get the address for the new file is depend on the file type,
00 file, BA file and CO file. Any way, don't forget to set up
the directory flag when you register the new file.name.
Otherwise someone, Menu, BASIC or TEXT and so on~ will destroy
your new file without any caution.

Refer to •Directory construction·.

8.2.2 How To Make DO File

If you have already registered the file name and


directory flag at the slot in the directory area, now the only
one information lacking in the new directory area 1s the
address of the new DO file. If you didn't read "Hou to
Register The New File Name" and you have not set the file name

- 106 -
F'
l RAM FILE HANDLING
........
and directory flag yet, please read that section and make up
them first.
Usually the new DO file is created just above the
ASCTAB, the lowest address of the-:existed DO files. Refer to
the figure in the ·what is RAM file· to make sure your image.
If you go with the standard rule which Menu, BASIC and others
in ROM #0 is used, you can copy the contents of the ASCTAB-1
as the starting address of the new files. Then the
registration of the new DO file is done completely. The
reason why we have to use ASCTAB-1 instead of ASCTAB is to
maintain the order of the files. The LNKFIL, to make up
starting address in directory area, searches the file name
from top to end and links the starting address of each file.
For LNKFIL searches the directory from younger address to
older address and older file has younger address, the order of
the DO file will be swapped if you use ASCTAB instead of
ASCTAB-1. Refer to •LNKFIL• in •useful Routine for RAM file
handling in ROM #0".
But you have to do two more steps for that new DO
file. One is to insert the end of file flag at the bottom of
that new DO file. Another one is, as you know, to make up the
starting address of other files in the directory area.
There is no DO file whose size is zero, because the
final character of the DO fiie should be AZ (AX1A, 26 in
Decimal). In other words, the AZ indicates the End of File of
the DO file. So the DO file will spend one byte at least. If
you only want to open the new DO file without any data, you
have to insert a AZ at the starting address. If you want to
save some data now, you have to append a AZ at the end of the
data. Never forget to insert a AZ at the end of the file.
Otherwise, next RAM file operation might destroy the all RAM
files.
In order to make a room for the new file, a convenient
routine is in the ROM #0. Its name is MAKHOL, MAKe HOLe.
This routine makes a hole from the specified point and whose
size can be decided by the contents in CBCJ register. Refer
to ·MAKHOL• in ·useful Routine For RAM file handling in ROM
#0·. The concept of the MAKHOL is shown briefly in that
section.

If there is no free area in RAM, and you cannot insert


a AZ, you cannot continue to enter data to the file. And, of
course, you have to clear the directory flag for next user.
To make up the starting address in the directory area,
the routine named LNKFIL is ready in ROM #0. The flow diagram

- 107 -
RAM FILE HANDLING
........
of that routine is shown in the ·useful Routine For RAM file
handling in ROM #0·. You can get information to make your own
LNKFIL routine in it, too.
If you succeed to insert 6 AZ and to make up the
etarting address field in the directory, the opening a new 00
file ha~ been done successfully. You can save the data to the
new file with using MAKHOL and LNKFIL. Refer to another
section to know how to Append, Insert, and Delete data. The
sample program in the following section will show you how to
make a new file and save data.
Cf. How to make a new DO file
1. Find a free slot in the user's directory. If you
cannot find a free slot in the directory area, you
have to give up to make a new DO file. Or if you
find the same name in the directory, delete that
file or abandon to continue.
2. Register the file name and directory· flag at the
free slot.
3. Get the ASCTAB-1 and·save it in the address field
of the elot.
4. Try to make a one byte hole at the address where
ASCTAB pointed.
5. If you fail to make a hole, clear the directory
flag which you registered at (2).
6. If you succeed to make a hole, insert a AZ at that
point.
7. Make up the pointers and starting address in the
directory area.
8. Tha~'s all. The new 00 file has been created
without fail.

NOTE: If you make a hole by your own routine, please


make sure that the your own routine refines the
pointers. Refer to the explanation about the MAKHOL.
And refer to ·LNKFIL• to know how to make up the
address in Directory.

- 108. -
f RAM FILE HANDLING

8.2.3 How To Make A BA File

There is few difference between how to make DO file


and How to make BASIC file. There is no difference in the
registration of the file name and the directory flag. The
first· difference is that you have to end the BASIC file with
double NULLs (0) instead of AZ in DO files. In order to
understand what double NULLs means, you·have to familiar with
the function of the LINK POINTER in the Microsoft BASIC. The
inner specification of the Microsoft BASIC file 1s too
difficult to described here briefly. You can get some good
texts to learn the information about the BASIC programs and
their data constructions at the book store or the computer
shop. But the ba$ic concept about RAM file handling is
exactly same as DO file. ( Register the file name and another
information at the directory and make a room for the program.)
The second difference is the new BA file is created
just above the BA files which has already stored. In other
words, the new BA file is inserted just below the lowest 00
file. Refer to the section, •wHAT IS RAM FILE?•,
I believe that the person who wants to handle the BA
files, is an expert about the BASIC program and BASIC
interpreter. If you are a novice class programmer about the
BASIC interpreter, you had better not try to handle the BA
file yourself. Please use BASIC mode in ROM #0.

ex. How to create a new BA file in PC-8201A


1. Search a free slot in the user's directory area.
If you find a same name in the directory area,
delete the file or abandon to continue.
2. Set.up the directory flag and copy the file name··
into the directory,
3. Copy ASCTAB -1 into NULDIR, non-register program's
directory area. And make 2 bytes hole and store
the double NULL for non-register program.
4. Make a hole as large as possible at the ASCTAB-1.

.. 5. The size of that hole is too small for the new BA


file, clear that directory flag written in (2).

- 109 -
RAM FILE HANDLING

6. If you succeed to make a big hole for your BA


file, copy the BASIC program into the hole. Don't
forget to insert the double NULLs at the end of
the program •
. 7. Register the starting address at the starting
addres~ area in the directory area. Usually-, the
address that is one byte less than the starting
address of the non-registered program is used.
8. Squeeze the hole, when you made a too large hole.
9. Adjust the pointers, ASCTAB, SINTAB, VARTAB,
ARYTAB and STREND. Make up the starting address
of other files in the directory area. All DO
files' and CO files' starting address in the
directory field should be changed. Refer to
LNKFIL.
10. End

- 110 -
RAM FILE HANDLING

8.2.4 How To Make A CO File

The CO file is the another type of the file which you


want to make _yourself beside the DO file. ·The difference
between DO file and CO file is the heading instruction of the
file. · The CO file needs the heading data instead of the End
of File character, AZ. So you have to make sure that there
are more than 6 bytes besides the size of your machine
language program in the free area. And if there is no enough
free area, you cannot continue to make a new CO file. If you
have already set up the directory flag and file name, clear
them soon. Don't leave the illegal flag and file name in the
directory.

Heading of CO file
START ADDRESS 2 bytes

LENGTH 2 bytes

EXECUTION ADDRESS 2 bytes

So the file length of CO file can be calculated by


LENGTH + 6. In making CO file, don't forget to renew the
pointers, VARTAB ,ARYTAB and STREND.
The CO file is usually made just under the address
pointed by VARTAB. So the starting address of the other files
need not be changed after saving new CO file. But I recommend
to do LNKFIL after ~aving new CO file for safety.

ex. BSAVE •MAC.,50000,10,50000 in BASIC mode


Dump the data in CO file is;

AXC350 (50000) Starting address


AX000A (10) Length
AXC350 (50000) Execution address

- 111 - -
RAM FILE HANDLING

Cf. The flow of making a new CO file

1. Search the free slot in the directory area. If


there is the same Tile name in the directory,
delete that file or abandon to continue.
2. Check the free area. Estimate the free size is
greater than your CO file's length+ 6 bytes.
3. If there is no room, stop.making a new CO file.
4. Make a hole just under address pointed by VARTAB
and store the data (or machine language program).
Make sure that all pointers are proper. In this
time, if you use MAKHOL to make a room, you have
to adjust the pointer, BINTAB. Because MAKHOL
changes BINTAB always.
S. Register the file name; directory flag and start
address at the directory.
6. Adjust VARTAB, ARYTAB and STRENO. Make up the
starting address of a 11 other files in the
directory for safety. If you use LNKFIL for-
adjustment of the a 11 start addresses in
directory, you have to care about the BINTAB as
you do in MAKHOL.
7 • . That ' s a 1 1 •

- 112 -
RAM FILE HANDLING

8.3 HOW TO DELETE A FILE


You can guess how to delete a file from the RAM file
•system in PC-8021 easily. The things that you have to do are
to clear the directory flag and to remove the data of the
file.
To delete a directory entry, you only turn off the
directory flag. If the. directory flag is less than AX80,
other programs regardes that slot is not used now.
And when you squeeze the body of the file, you have to
check the pointers and the start address of other files in the
directory. When you are using the subroutines in ROM #0,
these pointers are adjusted automatically. But if you do it
by your own routine, you have to care about the pointers. You
can find the good .clues in 'How to make new file", and
'MAKHOL' in 'Useful Routines for RAM file handling in ROM #0".
Whether you treat the pointers by your own routine or
utilize the MASOEL in ROM #0, you have to make up the starting
addresses of the another files. The LNKFIL will do it well.·
Refer to the following section to know the ENTRY information
about the LNKFIL. That section will give you a clue what
LNKFIL should do when you will make a LNKFIL by yourself.

8.3.1 How To Delete A 00 File

At the first, search the file name which you want to


delete in the file. If you don't remember the directory
construction, please refer to the chapter 'DIRECTORY
CONSTRUCTION", and make sure it. When you find the file name
in the directory, check the directory flag of the file. The
file which is opened in BASIC, cannot be deleted. If you do
it by force, the RAM file system might be crushed or the
system might be hung up.
Cf. The flow of d~leting a DO file (Calling Machine
language program by USR function in BASIC.)
1. Search the file name in the directory

- 113 -
RAM FILE HANDLING

2. Check the directory flag and if the file is opened


by BASIC, you cannot delete it.
3. Get the starting address of the file
4. Search AZ <End of File)
5. Count the size of the file
6. Remove the data of the file and shrink. The ROM
routine MASOEL will do it automatically. MASOEL
changes the pointers, BINTAB, VARTAB, ARYTAB and
STRENO automatically.
7. Refine the starting address of other files.
LNKFIL will help you.
8. Clear the directory flag of the file which you
deleted.
9. That~s all

8.3.2 How To Delete A BA File

When you are not in BASIC program, there is few


differences between killing 00 file and killing BA file. The
differences are in searching the end of file. In 00 file, AZ
(26 in decimal) indicates the End of file. But in BA file,
there is no such a good terminater. The only one way to get
the end of the BA file is tracing the ·1ink pointer· from the
beginning of the BA file to end. If you can utilize the ROM
#0, you may use the useful routines, CHEAO. The CHEAO
searches the end of the BA file. And MASDEL removes the data
and refines the pointers. You have to care about the TXTTAB
position. If you delete a BA file which is located under the
file pointed by TXTTAB, you have to adjust the TXTTAB. This
case is occurred when TXTTAB points the second BA file and you
delete the first BA fil&. Finally, you have to do make up the
all starting address Clink pointers) in directory area.
LNKFIL will do it.
NOTE: MASOEL does not change the ASCTAB. When a BA
file is ·killed, ASCTAB should be changed. So after

- 114 -
RAM FILE HANDLING

calling MASOEL, you have to adjust the ASCTAB. Refer


to the sample program in the following section. Also
·How to make a BA file· will give you a clue.
Another difference is that there is a limitation in
deleting a BA file when you are executing that BASIC program.
The following caution is ~vailable when you make a machine
language subroutine for a program written in BASIC. If you
won't make a machine language subroutine which handles the
BASIC file, you may skip to read this caution.

NOTE: You cannot kill the BA file when you are in


it. In other words, when you are running a machine
language subroutine with a BASIC program, you may not
delete that BASIC program in the subroutine. I'm
afraid that this explanation will not make sense for
you. So I will show you the short sample.

In the BASIC mode, you can know ~here you are


in by •FILES• command. The file name with •*• is the
current file which you are treating. You don't kill
it.

1. Select BASIC mode in the menu


2. Type a BASIC program.
10 PRINT •HELLO• .
3. Save it.
SAVE .TEsr·

4. Load it again.
LOAD .TEsr·

5. Try to kill it
KILL •TEST.BA• (Return>
?FC Error
Ok
6. This result show you what I want to say. SASIC's
KILL command checks the current TXTTAB and avoid
to kill himself. Your machine language routine
should do same check before killing a BASIC file.

- 115 -
RAM FILE HANDLING

NOTE: The comparison between TXTTAB and the


starting address of the BA file is available only when
you are executing the BASIC program or executing the
machine language subroutjne in BASIC mode. It is
meaningless to care about- the TXTTAB and starting
address when you are not in BASIC mode,

Refer to ·what is RAM file· and ·aookkeeping area· to


understand the position of the BA files and TXTTAB.

Cf. The flow of the deleting the BA file

1. Search the file name in the directory


2. Check the directory flag and if the file is not SA
file, of course, you cannot delete it.
3. Get the starting address of the file in the
directory
4. Compare that starting address to TXTTAB. If they
are identical, you cannot delete it. If not, you
have to remember which is larger, the starting
address or TXTTAB.
5. Search End of the File
CHEAO will help you to find the end of file.
Refer to ·useful Routines for RAM file Handling in
ROM #0•.

6. Count the size of the file


7. Remove the data of the file and shrink.
The ROM routine MASDEL will do it automatically.
MASDEL changes the pointers, BINTAB, VARTAB,
ARYTAB and STRENO. Refer to •what is RAM file•
and ·eookkeeping area·. And MASDEL returns the
negative length in BC register~ You can use it to
adjust the ASCTAB.
8. Adjust ASCTAB
9. Refine the starting address of other files.
LNKFIL will help you. Refer to "Useful Routine
For RAM file handling in ROM #0".

~ 116 -
:Restore the result of the comparison between the
:starting address of the file and TXTTAB. If
· ;TXTTAB is greater than the starting addres, adjust
.: it.
. ..
Clear the directory flag of the file which you
!deleted.
: That' e a 11

To DELETE A CO File

· don't have to care about where you are in now like


file or killing DO file. You may delete any CO
nt to delete, even if you are executing that co
, CO f i 1e· is 1oaded at the specified area when the
6ked in menu mode or in BASIC mode. So the ·co·
delete the ·co· file itself, and can save the free

'!

- 117 -
RAM FILE HANDLING
..
ex. Delete a CO file it9elf

1. Load a CO file in BASIC or MENU.

----------------- AXFFFF
-----------------
I
I

: machine prog I
I

:<-- BLOAO
or

Select
=================
: CO2 file
in
-----·------------ MENU
CO fi 1e :-:
BINTAB->: I
I

I
I
00 file9 I
I

--------------
BA file9 .,
I

AX8000 ---------~-----
Fig 8.1

- 118 -
,-
/
:hine prog

---------------- AXFFFF
=================

machine prog
<-- PC

<- STRENO

=================
CO2 file <- "XAAAA

CO file
<- BINTAB

00 files

I
~ I

BA files
:000 -----------------

Fig 8.2

119
r
~··

RAM FILE HANDLING

3. Delete the CO·file and move the data between the STRENO and
"XAAAA.

----------------- AXFFFF
=================
I I
I I
: machine prog :<- PC

<- STRENO

-----------------
I
I

: CO2 file
<- BINTAB
I.
I

00 files

BA files
AX8000 ----------~~--
Fig 8.3
NOTE: PC means Program Counter

- 120 -
RAM FILE HANDLING

Unfortunately, you cannot use MASOEL simply for


shrinking the hole which is made by killing the CO file, like
in deleting a BA file and a 00 file. Because MASOEL changes
the pointer, BINTAB. ( You can understand why BINTAB should
not be changed by reviewing the sec~ion, 'What is RAM files'
1
and Bookkeeping area'.) So if you want to use MASDEL, I do
recommend that, you have to save the BINTAB before calling
MASOEL and restore it after calling MASOEL.

Cf. The flow of deleting CO file.

1. Search a file name which you want to delete


2. Save the starting address in the airectory
3. Calculate the size of that file. The 2nd and 3rd
byte in that file show the data length. So the
total size of the file is made by adding 6 bytes
to the data length. (The 6 bytes includes the
starting address, data length and the execution
1
address. Refer to What is the RAM file.·)
4. Set the starting address and the length for MASOEL
s. Save BINTAB
6. Call MASDEL
7. Recover BINTAB
8. Clear the directory flag of the file
9. That's all

- 121 -
RAM FILE HANDLING

8.4 HOW TO APPEND DATA TO 00 FILE"

The way to append data to the 00 file is very easy.


At the first, get the starting aadress of the 00 file in the
directory and search the end of file, AZ. Then, make a room
for data you want to store at that point. The routine,
MAKHOL, is a best routine to-make a room. Refer to ·useful
Routine For RAM file handling in ROM #0•. And don't forget to
refine the starting address of other files in the directory
area. LNKFIL will help you. Refer to previous chapter, ·How
to make a DO file· also.

Cf. APPEND data to the 00 file


1. Search the file name in the directory
2. Make sure the file type and status by checking the
directory flag.
3~ Get the starting address in the directory
4. Search the end of file, AZ ( 26 in Decimal)
5. Make a hole_just before the AZ.
I recommend to use MAKHOL.
6. Store data in the hole
7. Shrink the hole, when the hole you made 1s too
large for the data ·

MASOEL in ROM #0 is useful.


8. Refine the starting address in the Directory area.
LNKFIL will help you.
9. End

There is a sample program of how to APPEND data to 00


file in the foll~wing section.

- 122 -
RAM FILE HANDLING

8.5 HOW TO INSERT DATA TO DO FIL~

When you want to insert some data to the DO file, you


can use the know-how which you Wse to APPEND data to the DO
file. The difference is that you have to search the address
where you want to insert the data instead of searching the end
of file.

Cf. Insert data to DO file


1. Search the file name in the directory
2. Make sure the file type and status by checking the
directory flag
3. Get the starting address in the directory
4. Get the address where you want to insert the data
5. Make a hole for the data at the point
Usually, MAKHOL in ROM #0 is used. MAKHOL changes
the pointers, BINTAB, VARTAB, ARYTAB and STREND.
6. Copy data in the hole
7. Shrink the hole, when the hole is too large for
the data
MASOEL in ROM #0 is useful. MASOEL adjusts
the pointers, BINTAB, VARTAB, ARYTAB and STRENO.
8. Adjust the starting address in the RAM.
LNKFIL in ROM #0 is useful. Refer to "Useful
Routines for RAM file Handling in ROM #0".
9. End

- 123 -
...
RAM FILE HANDLING

8.6 HOU TO DELETE DATA FROM DO FILE


To DELETE data from the 00 file is easier than to
INSERT data to the 00 file. If you will use the ROM #0, the
routine named MASDEL delete the da~a. The MASOEL refines the
pointers and LNKFIL adjusts the starting addresses of other
file's. You can find the detail information about MASDEL and
LNKFIL in ·useful Routine for RAM file in ROM #0. If you
cannot use the ROM #0, you have to renew the pointers, BINTAB,
VARTAB, ARYTAB and STRENO by YOURSELF. And you must modify
the starting addresses in the directory YOURSELF. Refer to
the chapter ·oirectory construction· and "Bookkeeping• to
under stand the directory structure and pointers. "MAKHOL"
and "LNKFIL• in ·useful Routine for RAM file handling in ROM
#&" show you how to do it •

- 124 -
RAM FILE HANDLING

8.7 USEFUL ROUTINES FOR RAM FILE HANDLING IN ROM #0

There are several useful routines in ROM #0 for RAM


file handling. ·Indeed that you have to do 'bank-switching' to
use these RAM file handling routines from ROM #1. (Refer to
Chapter 3.3) But you don't have to worry about the pointers,
if you use them. And also, you can save the time to make your
own subroutines. I do recommend you to use these RAM file
handling routines in ROM #0 for saving time and making
applications smoothly.

The presented useful routine in ROM #0.


MAKHOL: Make a room for data entry with changing the pointers
LNKFIL: Make sure the start addre~s in the directory area
MASDEL: Shrink the room made by MAKHOL. This file help you
when you made a too large hole.
CHEAO: Search the end of file in BA file.

- 125 -

l
RAM FILE HANDLING

8.7.1 MAKHOL

Make a hole
ADDRESS AX6C0A C AO66012, 27658 >
ENTRY CHLJ points where you want to make a hole
CBCJ size of the hole
EXIT CHLJ and CBCJ are preserved
Carry is set if out of memory
In order to know the free area's size, STRENO
is the best pointer. The amount of the STRENO and
your file's size, in this case, should be less than
CSPJ 120. (The ·sp• means Stack Pointer, as you
know. ) The 120 bytes are reserved for Stack's
operation. If there is a enough room, MAKHOL shifts
the all data between the specified address and STRENO.
If not,· MAKHOL returns with carry set. The flow of
MAKHOL is listed at next page.

- 126 -
RAM FILE HANDLING

ex. The flow of MAKHOL. tHow to make a room safely.)

/------------¥
MAKHOL
¥------------/
; STRENO + Required bytes
< SP - Stack area ( 120 bytes) :
I
I No
: -----.----> Out of Memory

: Move the data between STRENO and


specified address

-------------------------------------
Change the pointers
**
ASCTAB, BINTAB, VARTAB, ARYTAB
and STREND
-----------------~-------------------
-/-----------¥
RETURN
¥-----------/
Fig 8.4

It is unnecessary to care about the pointers


unless you make your own MAKHOL routine. The MAKHOL
in ROM #0 manages the pointers automatically. But it
does not change the starting address in the directory
field. Refer to LNKFIL.

·**When you make a hole just above the ASCTAB to


create a new DO file, you have to change the
pointers, BINTAB, VARTAB and ARYTAB. The ASCTAB
is modified only when you make a hole under ASCTAB
to register a new BA file.

- 127 -
RAM FILE HANDLING

It is ~asy to guess that calling MAKHOL too many times


will reduce the processing speed. So you had better call the
MAKHOL with a good large number in BC register. It makes a
good hole which is large enough to save the data you want to
keep. The only one thing you have to care of is that you have
to shrink the hole when you made a too big hole. The 00 file
cannot include NUL (0) and AZ (26) in the file. (The AZ means
the End of File, as you know.) There is a convenient routine
to shrink the hole and it refines the pointers, also. Its
name is MASOEL and you can get the information about it in the
following section.

- 128 -
RAM FILE HANDLING

8.7.2 LNKFIL

Fix up directory structure


ADDRESS AX233A < A021472, 9018 >
ENTRY: NONE
EXIT : NONE
All registers might be altered

This routine fixes up all possible incomplete "links"


between files and their directories. There are many chances
in that the link pointers ( same as starting address>. in the
directory fields are not maintained properly. For instance,
Making a new DO file will change the starting address of other
00 files and CO file. I agree that these link pointers should
be modified every time when the RAM organization is modified.
But it is also true that such a operation will make a big
overhead in RAM file handling. Since you had better make sure
when LNKFIL should be called. For instance, when a file is
deleted during further file I/0, all link pointers should be
fixed up.

- 129 -
RAM FILE HANDLING

Internal flow of LNKFIL

/---------------¥
LNKFIL
¥---------------/
Mark the all valid directory:
: flag (turn 0 bit of all
: valid directory flag)

: Get the lowest file address:


~-----------------------------
Get the lowest link pointer
in the valid file's
directory

: Save this link pointer r

:<------------------------------·
Search the lowest link pointer:
: in the marked files in
: directory area

---------------------------
Save the saved link pointer
at this marked files link
pointer field ·
---------------~-----------------
I
I
:

Demark the directory flag of


: that file. (turn off the bit 0:
: of that file)

(A) (8)

- 130
RAM FILE HANDLING

CA) (8)

l Get next lowest file address l


l from the bottom of RAM l·
--------------------------------
-----------------------------
l All marked directory flag
l has demaked?
--------------------------------
Not End of directory

l End of directory

/---------------¥
ENO
¥---------~----/
Fig 8.5

When the top address of ~he next file is searched, the


pointers, ASCTAB and BINTAB are useful to know what kind of
file is searched now.

- 131 -
RAM FILE HANDLING

8.7.3 MASOEL

Delete CBCJ bytes from CHLJ


.
ADDRESS: AX6C3C C A066074, 27708)

ENTRY: CHLJ pointer of the hole should be squeezed


CBCJ size of the hole
EXIT: CHLJ preserved
CBCJ negated

This routine do exactly reverse operation of


MAKHOL. The data above the CHLJ+CBCJ is moved up.
And the pointers, BINTAB, VARTAB~ ARYTAS are modified.
If you use this routine for shrinking a hole of BA
file, you can adjust the ASCTAB with the negated CBCJ _
after exit this routine. And also you can adjust the
TXTTAB by using this negated BC register if necessary.
You have to adjust the TXTTAB when you remove a BA
file which is located under the address where 1s
pointed by TXTTAB.
If you want utilize this routine for CO file,
you need save BINTAB and recover it after exit. The
BINTAB is not modified by killing CO file.

- 132 -
RAM FILE HANDLING ,

8.7.4 CHEAD
...
Search for the end of this BASIC program
ADDRESS AX718 C 34300, 1816)

ENTRY·: CHLJ Top address of that BASIC file


EXIT: CHLJ The last address of that BASIC file
All registers and flags are modified possibly

The main purpose of CHEAD is fix links of the


BASIC program. In other words, CHEAD goes through
program storage and fixes up all the links. The end
of each line is found by searching for the zero at the
end. The double zero link is used to detect the end
of the program. So EXIT CHLJ and one will show you
the top address of the next file.

- 133 -
RAM FILE HANDLING
--~
8.8 SAMPLE PROGRAM

The sample ,programs listed here are the exactly


·sAMPLE·. So some processes are omitted to make explanation
clearly. For instance, searching directory to find the good
slot for file handling is not described except ·How to make a
DO file·. You know that you have to survey the all directory
for checking the same file name and free slot, when you make a
new file.
And also, these programs, stored this section are
written in plane program technic. You will find another good
algorism to handle the RAM files safely and quickly.

- 134 -
RAM FILE HANDLING

8.8.1 Make A New 00 File (ASCii File)

; Register new DO file in the Directory area


; OPEN DO file
;
USRDIR EQU AXF891 ;Top address of user's
;directory
EOTDIR EQU USROIR - Directory length
OIRLEN EQU 11 ;Length of the directory per
file
NAMLEN EQU 6 ;Length of the file name
ASCTAB EQU AXFAE1 ;Points the lowest address of
;DO files
LNKFIL EQU AX233A ;Make up the address 1n
;Directory
MAKHOL EQU AX6C0A ;Make a room for file
EOFFIL EQU A1AH ;End of 00 file
OPENDO:
XRA A ;Clear HL
MOV H,A ,•
MOV L,A . ,•
SHLO SLTAOR ;Clear slot address
,•
LXI H,EOTOIR ;Set Ctop of user directory]
; - Directory length
SEANAM:
LXI B,OIRLEN;Set Directory length
DAO 8 ;Get next slot
MOV A,M ;Get directory flag
CPI AX80 ; Va 1 id?
JC NONVAL ;Jump if not valid slot
INR A ;End of directory area?
JZ ENOSEA ;Jump if end of test
,•
; Is the file DO file?
OCR A ;Adjust directory flag
MOV D,A ;copy flag for later use
AN! AB01000000
;Pick up ASCII flag
ORA A ;DO file?
JZ SEANAM ;Jump if not DO file
,•
,• Compare the name
,•
PUSH H ;Save the slot address
INX H
INX H ;Advance to name field in

- 135 -
RAM FILE HANDLING

; directory
XCHG ;COEJ name address
LXI H,NAME ;name of the file which
; we want to make
MVI B,NAMLEN;Set name ~ength
CMPNAM:
LOAX 0 ;Get directory's name
CPI M ;Compare with our file
JNZ NOTSAM ;Jump if not same
INX H ;Advance the pointers
INX 0
OCR B
JNZ CMPNAM ;compare next
,•
; Same file name is found
,•
POP H ;Top of the slot address
MOV A,M ;Get directory flag
ANI AB00000010
;Pick up OPEN BIT
ORA A ;File already opened?
JNZ FILAOP ;Jump if file already opened
,•
; Find same name and not opened file
,•
SHLO SLTAOR ;Save it
-CALL OELFIL ;Delete this file
· JMP FINONM ;go to Registration
,•
; Find free slot
,•
XCHG ;COEJ free slot address
LHLO SLTAOR ;Get free slo.t address
; that has been found
MOV A,H ,•
ORA L ;Never found?
JNZ EVERFN ;jump if already found
XCHG ;This is the fir-st time
SHLO SLTAOR
JMP SEANAM ;Check next slot
,•
EVERFN:
XCHG ;Don't renew the address
JMP SEANAM ,•
; To search the directory is done
,•
LHLO SLTAOR ;Is there good free slot?
MOV A,H
ORA L ,•

- 136 -
RAM FILE HANDLING.
4

JZ OIRFULL ;Jump if directory full


;
PUSH H ;Save the top of the slot
MVI M,"'811000000
;Set directory flag as 00
; fi l·e
INX H ;Advance to name field
INX H
LXI O,NAME ;Top of our file name
MVI B,NAMLEN;Name length
CPYNAM:
LDAX 0 ;get our file name
MOV M,A ;copy it in directory
INX H ,•
INX D
OCR B ;Continue to end of name
JNZ CPYNAM
•,
LHLD ASCTAB ;Get lowest address for 00
; files
LXI 8,1 ;Make one byte hole
CALL MAKHOL ;Dig
JC MEMFUL ;Jump if out of memory
MVI M,EOFFIL;Set end of file marker
DCX H ;Lowest address - 1
; for maintain the file order
POP D ;Recover Top of that slot
INX D ;Advance to address field
MOV A,L ;set start address
STAX D
INX 0
MOV A,H
STAX 0
,•
; Make up starting address of other files in
,• directory area
;
CALL LNKFIL
RET
;
; External routines

'
DELFIL:
; Delete the specified file
FILAOP:
; Error handling --- File already opened
MEMFUL:

- 137 -
RAM FILE HANDLING

; Error handling Memory ful 1


DIRFUL:
; Error handling --- Directory full
,•
..
; DATA AREA

'
NAME: DB 'TEST DO'
ENO

- 138 -
RAM FILE HANDLING

8.8.2 Save Data Into DO Fi 1e . --


;' Save data into DO file

;' ENTRY: CHLJ points directory of the file
,• CDEJ address of source data
• CBCJ length of data
'•
'
MAKHOL EQU AX6C0A ;Make a room for data
LNKFIL EQU AX233A ;Make up starting address
ENDFIL EQU AX1A ;End of DO file
•t

'
SAVDAT:

.
'•; Check the directory flag of the file

t
MOV A,M ;Get directory flag
PUSH B ;Save data length
MOV B,A ;Save directory flag
ANI Ae11000000·
;Pick up mode bits
CPI AB11000000
;DO file?
JNZ BADFIL ;Jump if not DO file
MOV A,B ;Get flag again
ANI AB00000010
·;Pickup OPEN bit
ORA A ;File already opened?
JNZ FILAOP ;Jump if file already opened
MOV A,B ;Get directory flag
ORI 000000108
;Say this file is opened
MOV M,A

';Search end of file

' POP B ;Recover DATA length
PUSH H ;Save Top of directory address
PUSH B ;Save DATA length
INX H ;Advance to Address field
MOV A,M ;get address in CHLJ
INX H

- 139 -
I
RAM FILE HANDLING

MOV H,M
MOV L,A ;Set top of the file
,•
SEALOP:
MOV A,M ;Get Data
CPI ENDFIL ;End of file?
JZ FNDEOF ;Jump if end of file
INX H
JMP SEALOP ;Search next
,•
;MAKE A ROOM FOR DATA
,•
POP B ;Recover data lengtH
PUSH D ;Save source address
CALL MAKHOL ;Dig a hole for data
JC MEMFUL ;jump if error detected
POP D ;Recover source address
,•
;copy data in to the hole
,•
COPYLP:
LDAX D ;Get source data
MOV M,A ;save it in~o file
INX H
INX D
DCX B ;Decrement DATA length
MOV A,B ,•
ORA C ;End of data?
JNZ COPYLP ;Continue till end of data
,•
;Make up starting address of other files in
; directory area
,•
CALL LNKFIL
•,
;Turn off the opened bit in directory flag
•,
POP H ;Recover directory address
MOV A,M ;Get directory flag
ANI ~B11111101
;Turn off the flag
MOV M,A ;Renew the flag
RET
,•
;External routines
,•
BADFIL:
; Bad file mode

- 140 -
RAM FILE HANDLING

FILAOP:
.
; File already o~ened
MEMFUL:
; Memory full error..
ENO

- 141 -
,
..
RAM FILE HANDLING

8.8.3 DELETE SOME DATA FRoM·oo FILt

...
Delete some data from DO file
ENTRY: CHLJ Top of the direetory address
CDEJ Offset address of Top data
should be deleted
; CBCJ Length of data should be deleted
,•
MASOEL EQU AX6C3C ;Remove some data
LNKFIL EQU AX233A ;Make up starting address
,•
OELDAT:
,•
;Check directory flag
'• MOV A,M ;Get direetory flag of
; the file
ANI AB11000000
;Pick up VALID bit and ASCII
; bit
CPI AB11000000
;Valid 00 file?
JNZ BADFIL ;Jump if bad file
MOV A,M ;Get direetory flag again
ANI A800000010
;Pick up OPEN bit
ORA A ;Already opened?
JNZ FILAOP ;jump if the file already opened
MOV A,M ;Set opened bit
ORI AB00000010
MOV M,A ;Say, the file is opened
,•
PUSH H ;Save directory address
INX H ;Get start address of the file
MOV A,M •
'
INX H
MOV H,M ,•
MOV L,A ;CHLJ start address of the file
;
DAD D ;Absolute address of the data
; ~hich should be removed
; Delete data
,• CHLJ TOP of the data, CBCJ data length
•,

- 142 -
RAM FILE HANDLING

CALL MASOEL ;Remove the data from file


,•
; Turn off the OPENED bit
,•
POP H ;Restore .the directory address
MOV A,M ;Get d1rectory flag
ANI AB11111101
;Turn off
MOV M,A
,•
;Adjust the directory
CALL LNKFIL ;Make up all 9tart address in the
; directory flag
,•
RET
,•
; External routine
,•
BADFIL:
;Bad file mode -- Error
FILAOP:
;File already opened -- Error

- 143 -
RAM FILE HANDLING

8.8.4 DELETE 00 FILE



; Delete 00 file
•,
; ENTRY.: CHLJ points the directory of the file
,•
MASOEL EQU AX6C3C ;remove data
LNKFIL EQU AX233A ;adjust address field in
; directory area
DELOO:
MOV A,M ;Get directory flag
ANI AB11000000
;Pick up VALID and ASCII bit
CPI "811000000
;Valid do file
JNZ BADFIL ;jump if bad file mode
MOV A,M ;get directory flag
ANI AB00000010
;pick up opened bit
ORA A ;Already opened?
JNZ FILAOP ;jump if already opened
,•
; Calculate the size of the file

• PUSH H ;save directory address
INX H ;get start address
MOV A,M ,•
INX H
MOV H,M ;CHLJ start address
MOV L,A
;
PUSH H ;Save start address
SEALOP:
MOV A,M ;end of file?
CPI EOFFIL ,•
INX H ;next field
JNZ SEALOP ;continue till EOF
,•
POP 0 ;Restore start address
MOV A,L ;CHLJ-CDEJ= length
SUB E:
MOV C,A
MOV A,H ,•
S88 0
MOV 8,A ;Set length in CBCJ

- 144 -
tlAN~LING

XCHG ;CHLJ star·t" address


,•
CALL MASOEL ;Remove the data
•,
POP H ;recove_r directory address
XRA A
MOV M,A ;clear it
,•
;Make up all start address in directory
,•
CALL LNKFIL
,•
RET

'
;External routine

'
FILAOP:
;File already opened error
BAOFIL:
;Bad file mode error
,•
ENO

- 145 -
RAM FILE HANDLING

--·-s -•
8.8.S DELETE SA FILE


'
;Delete BASIC file - . . -l

;' Asswme that this subroutine i!s used with BASIC
I
• main program
,'•
; ENTRY: CHLJ directory address of the file
,•
MASOEL EQU "'X6C3C ; remove data from file
LNKFIL EQU "'X233A ; make up starting address
CHEAO EQU "X0718; search end of BASIC file
TXTTAB EQU "'XF45O ; lowest address of current
; BASIC program
A$CTAB EQU "XFAE1 ·; Lowest address of 00 files
,•
,•
OELBAS:
MOV A,M ;Get directory flag
c·p1 "B10000000
;BASIC file?
JNZ BAOFIL ;Jump if not BASIC
; file
XCHG ;COEJ directory address
LHLO TXTTAB ;get lowest address of the
;current BASIC program
; (Ue are executing the
; BASIC program with this
; machine subroutine.)
XCHG ;COEJ TXTTAB CHLJ Directory
; address
PUSH H ;save directory address
INX H ;advance to address field
MOV A,M ;get start address of BA file
; which we want to delete
INX H
MOV H,M
MOV L,A ;CHLJ start address
MOV A,H ;compare to TXTTAB
SUB D
JNZ NOSAM ;jump if not same
MOV A,L ;compare lower address
SUB E ,•
JNZ NOSAM ;jump if not same

146 -
RAM FILE HANDLING

JMP FCERR ;you cannot kill Y.Our mother


;BASIC
NOSAM:
XCHG ;save start address
POP H ;recover directory address
PUSH PSIJ ;save result of comparison
XRA A ;CAJ=0
MOV M,A ;clear directory flag
PUSH D ;save start address
,•
;COEJ start address of the BA file

' CALL CHEAO ;search the end of BA file
INX H ;adjust for calculation the length
POP 0 ;recover start address
PUSH 0 ;Save start address· again
MOV A,L ;Calculate the length
SUB E •
MOV C,A '
;Set length in CBCJ
·· MOV A,H
SBB D
POP H ; recov·er start address

';Remove body of the file

' CALL MASOEL ;return negative length in CBCJ

' LHLD ASCTAB ;adjust ASCTAB because MASOEL
;doesn't change it
DAD B
SHLO ASCTAB

' PUSH B ;save this value for later use

'
;Adjust starting address in directory

' CALL LNKFIL •
• '
'
POP B ;Restore adjustment value
POP PSIJ ;recall result of comparison
; TXTTAB and start address
RNC ;Return if TXTTAB is smaller
; than start address
LHLO TXTTAB ;Adjust TXTTAB because we
; delete BA file under TXTTAB
DAO B
SHLD TXTTAB
RET

'

- 147 -
RAM FILE HANDLING

; EXTERNAL ROUTINE

'
FCERR:
; Illegal function call error
••
BAOFIL:
; Bad file mode error
ENO

- 148 -
RAM FILE HANDLING

8.8.6 MAKE NEW CO FILE

-.
; MAKE NEW CO FILE
,•
; ENTRY: CSTRADRJ start address of CO file data
• CLENGTHJ length of data
'•• CEXECADJ execution address

•• CHLJ directory address for this CO file
•'
'
MAKHOL EQU "'X6C0A ;make a room·
LNKFIL EQU "'X233A ;make up directory address field
HEADLN EQU 6 ;Header length of CO file
BINTAB EQU "'XFAE3 ; 1owest address of existed co
• files
VARTAS EQU "'XFAES '; 1owest address of Variable
• table
'
MAKECO:
,•
; Refer HOU TO MAKE NEU DO FILE to know how to find
; the directory address for new files •

-'
MVI A,""B10100000
;Set direc~ory flag as CO file
MOV M,A ;register it
PUSH H ;save directory address
LHLD LENGTH ;get file l~ngth of new CO
LXI B,HEAOLN;Set header length
DAO B ;Get total length of new CO file
MOV B,H ;Set length in CBCJ
MOV C,L ;
LHLD BINTAB· ;CHLJ lowest address of existed
;CO files
PUSH H ;Save current BINTAB
LHLD VARTAB ;CHLJ just above highest CO file
CALL MAKHOL ;Try to make a hole
JC MEMFUL ;jump if there is no enough room
XCHG ;Save the top address of hole
POP H ;recover BINTAB
SHLD BINTAB ;Adjust BINTAB
XCHG ;restore TOP of hole

- 149 -
RAM FILE HANDLING

POP D
.. -·
;CDEJ directory address
INX 0 ;advance to address field
MOV A,L ;Set start address
STAX
INX
0
D
..
-
MOV A,H •,
STAX D
,•
; To register the file name in directory is omitted •
,•
XCHG ;COEJ top of the vacant room
MVI B,HEAOLN;Set header length
LXI H,STARAO;offset of header data
COPYHD:
MOV A,M ;Get header data
STAX 0 ;store'it in file
INX 0
INX H
OCR B ;end of header data?
JNZ COPYHD :copy 3 address as header
,•
LHLD LENGTH ;Get data length
MOV B,H , ;set length in• CBCJ
MOV C,!:ir-
LHLD STARAD ;CDEJ destination address
;CHLJ source address
COPYLP:
MOV A,M ;copy contents of file
STAX 0
INX 0
INX H
DCX B ;count down
MOV A,B ;end of data?
ORA C
JNZ COPYLP ;continue till end of data
,•
CALL LNKFIL ;make up all start address of
;other files in directory area
RET

'• ERROR HANDLING ROUTINE
'•
'
MEMFUL:
• memory ful 1 er-r-or-
'
,•
,• DATA AREA
,•
STARAO: OS 2
LENGTH: OS 2

- 150 -
RAM FILE HANDLING
-~
EXECAO: OS 2

ENO

- 151 -
RAM FILE HANDLING
.~

8.8.7 DELETE A CO FILE


;' DELETE A CO FILE
;
; ENTRY: CHLJ addres of its directory

'
MASDEL EQU AX6C3C ;remove data
LNKFIL EQU AX233A ;make up starting address
;in the directory
BINTAB EQU "XFAE3 ; 1owest address of CO files
HEADLN EQU 6 ; 1ength of the header in CO
• file
'
DELCO:
MOV A,M ;Get DIRECTORY flag
CPI "'810100000
;CO file?
JNZ BAOFIL ;Jump if BAO file mode
XRA A •
MOV M,A '
;Clear directory flag
INX H ;Advance to address field
MOV A,M ;Get start address of the CO
;file
INX H
MOV H,M ;CHLJ start address
MOV L,A
PUSH H ;s~ve start address
INX H ;Get file length in the
; header
INX H
MOV C,M ;get length in CBCJ
INX H •
MOV B,M '
LXI H,HEADLN;add header length
DAO B ;
MOV B,H ;Set total length in CBCJ
MOV C,L
POP H ;recover start address
XCHG ;save it at once
LHLO BINTAB ;get lowest address of existed
;CO files
PUSH H ;save it for after adjustment
XCHG ;CHLJ start address
;CBCJ file length
CALL MAS.DEL ;remove the body of the file
POP H ;recover BINTAB
SHLD BINTAB ;adjust BINTAB

- 152 -
RAM FILE HANDLING
;, - .. ·1

' CALL LNKFIL ;make up starting address in
;the directory area
RET
; EXTERNAL ERROR ROUTINE
,•
BADFIL:
;Bad file mode
END

- 153 -
r
!

CHAPTER 9
LCD INTERFACE

This chapter describes how to control LCD (Liquid


Crystal Display) of PC-8201A.

9.1 OVER VIEU

The LCD (LR-202C>, full bit map screen which consists


of 240 * 64 dots, displays 40 characters per line and 8
lines per screen. A character on the LCD consists of 6 by 8
pixels. The.LCD is driven by 10 Segment Drivers (HD441026)
with 200 bytes Display RAM and 2 Common Drivers (HD44023b).
Segment Drivers are selected by Port A/8 of PPI (81C55).

9.2 CONSTRUCTION OF LCD

. The LCD is divided into the following IC blocks. Each


block has i.ts own Segment Driver with 200 bytes Display RAM.
And each IC block can display 50 * 32 dots. However, BS and
B10 displays only 40 * 32 dots. Of course, you can write
dots on the remaining area of Display RAM of B5 and 810 with
no error, but they will never appear on the screen.

- 154 -
LCD INTERFACE

. ·•
:<------- 240 dots-------------------->:
-----+-------~-------------------------------+
I
I

81 : B2 B3 .
84 BS

64 dots+---------------------------------------+
I
I

B6: B7 BS 89 810

-----+---------------------------------------+
Fig 9.1

The Display RAM may be regarded as the VRAM 1n the


traditional desk top type personal computer. Setting a Bit
On/Off in the Display RAM means setting/resetting a dot on
the LCD.

Refer to following sections how to control ·each


Segment Driver.

- 155 -
r~~ LCO INTERFACE

. 9.3 I/0 PORT RELATED TO LCD ..

9.3.1 BLOCK SELECT PPI 81CSS . PORT A/8


··- .....

msb 7 6 5 4 3 2 1 0 lsb
+---+---+---+---+---+---+---+---+
lPA7lPA6lPASlPA4lPA3lPA2lPA1lPA1: OUT ""X89
+-------------------------------+
: X l X l X l X: X l X lP81lPB0l OUT ""XBA
+------------------------------+
PA0 to P87 is associated to 8LOCK1 to BLOCKS
P80,PB1 to BLOCK9,10 respectively.
0 = Not Select/ 1 = Select
Oescr-iption:
Selecting a LCD Block C same meaning as selecting a
Segment Driver IC) .which. you want to access. You
cannot select two blocks at a time.

- 156 -
LCD INTERFACE

9.3.2 LCD COMMAND SET

There are 5 commands to control the Segment Driver IC.


These commands are executed via Port ~XFE.

9.3.2.1 Display ON/OFF.

msb 7 6 5 4 3 2 1 0 lsb
+---+---+---+---+---+---+---+------+
: 0 : 0 : 1 : 1 : 1 : 0 : 0 : DISP : OUT "'XFE
+---+---+---+---+---+---+---+------+

DISP: Display ON/OFF


0 = Dieplay Off
1 = Display On
Description:
DISP decides ~hether the data in Display RAM
is displayed on the screen.
This port doesn't effect the contents of Display RAM.

- 157 -

/
LCO INTERFACE
-
9.3.2.2 Set Address Counter

msb 7 6 5 4 3 2 ·f · 0 lsb
+---+---+---+---+---+---+---+---+
lPG1lPG0lOFS:OF4lOF3:0F2:oF1:oF0:
+---+---+---+---+---+---+---+---+

Select PAGE
PGl PG0
0 1 PAGE0
0 1 PAGE1
1 0 PAGE2
1 1 PAGE3
OFn means 'OFfset counter' in each PAGE.
It must be from 0 to 49.

The Display RAM is divided into 4( 0 to 3) pages and


each page contains 50 bytes (0 to 49) as shown at next page.
Segment driver has PAGE counter and OFFSET Counter. These
counter is set by this command. The OFFSET counter works as
the loop counter, it's value· from 0 to 49. The OFFSET counter
is automatically Incremented/Decremented after read/write
operation. The counter mode is described blow. Page counter
is not changed by read/write operation.

- 158 -


LCD INTERFACE
,I

OFFSET counter- .
PAGE 0<------------------->49(39 if BS/810>
counter- +---+-------------------+
: 1sb: I
I
"800 I
I
I
I PAGE 0
:msbl
+---+---~---------------+
l lsb I
I
"B01 I
I PAGE 1
lmsb
+-----------------------+
: 1sb
"'B10 I
I PAGE 2
:msb
+-----------------------+
:meb
"'B11 PAGE 3
: 1sb
+-----------------------+
Fig 9.2

- 159 -
/
r
, LCD INTERFACE

9.3.2.3 Set Starting Page.

msb 7 6 5 4 3 -- 2 . 1~
0 lsb
+----+---+---+---+---+---+---+---+
lSPG1lSPG2l 1 : 1 : 1 : 1 l 1 : 1 : OUT "XFE
·+----+----+---+---+---+---+---+---+

SPG1/0: Specify the Starting Page to be


display on LCD.
SPG1 SPG0 Order of Display Page
0 0 0 -> 1 -> 2 -> 3
0 1 1 -> 2 -> 3 -> 0
1 0 2 -> 3 -> 0 -> 1
1 1 3 -> 0 -> 1 -> 2

Description:
Assume that each LCD block is divided into 4 pages
corresponding with the Display RAM. The combination
with the Page of LCD Block and Display RAM page can
changed. The •sET STARTING PAGE. defines the mapping
bet~een the Page in Display RAM and the Page of LCD
Block.

Ex.
Assume that Starting page is ~et to 2. Then mapping
bet~een Display RAM and LCD PAGE becomes as shown as
follows.

- 160 -
LCD INTERFACE

-LCD BLOCK
Upper +-----------------------+
.,
PAGE2 in Display RAM
is displayed here

+-----------------------+
PAGE3 in Display RAM
is displayed here

+-----------------------+
PAGE0 in Display RAM
is displayed here

+-----------------------+
..
I

PAGE1 in Display RAM


i9 displayed here
I
I

Lower +-----------------------+
Fig 9.3

- 161 -
LCD INTERFACE
....
9.3.2.4 Select Addre9s Counter Mode

m9b 7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
: 0 : 0 : 1 : 1 : 0 : 0 : 1 :u10: ouT AXFE
+---+---+---+---+---+---+---+---+

U/O(Up/Oown count) --- 0 Up Count


1 Down count
Description:
Set OFFSET Counter Mode.

-· 162 -
LCD INTERFACE
.,
9.3.3 Read Status Read The Status Of Segment Driver.

msb 7 6 5 4 -·~ 3 - 0 1sb


+----+-------+------+-----+-----+
lBUSYlUP/DOWNlON/OFFlRESETlXXXX: IN AXFE
+----+-------+------+-----+-----+
RESET
0
----- Sta~us of the RST pin
Normal
1 RST is low 1evel
(BUSY must be 1)
ON/OFF
0
----- Display ON/OFF
Display OFF
1 Display ON
UP/DOWN
0
----- Mode of Address counter
Down counter
1 Up counter
BUSY
0
----- Normal
1 Operating Command or
Writing/Reading a data.

- 163 -
LCD INTERFACE ··•
.,.
9.3.4 ~rite/Read Display Data

.. -·~-. .
~-
+--+--+--+-~+--+--+--+--+
:O7lO6lDSlD4lO3:D2lD1:O0: IN/OUT "'XFF
·+--+--+--+--+--+--+--+--+

Description:
Read the data from the Display RAM that is pointed by
PAGE and OFFSET counter. If you want read some portion
of the Display RAM, use this command after Setting t~e
PAGE counter and OFFSET counter by ·set Address
Counter· command and ·set Page Counter' command
described before. Note that one dummy read must be
done before using this command in order to get a
correct data.

- 164 -
LCD INTERFACE . .
9.4 SOFTWARE FOR LCD

; This section describes not ohly how to handle the LCD


without reading the routines stored in ROM #0 about LCD, but
also how to maintain the book-keeping area for LCD in the RAM.

9.4.1 How To Initialize The LCD.

What should be done in initialization is following.


1) Set up Address counter. Usually Page 0, Offset 0.
2) Set up Offset Counter Mode.
3) Set up Starting Page.
4) Select Display ON/OFF.

The tiny program shown blow initializes LCD's all


Segment Drivers as below.

PAGE COUNTER= 0
OFFSET COUNTER= 0
UP COUNTER MOOE
STARTION PAGE= 0
DISPLAY 0N

Note:
Whenever the power is turned on, LCD is initialized by
the reset pulse of the hard wear. At that time,
Display is turned OFF, Offset Counter is set to count
up mode. Another status is not determined.

The ROM #0 always reinitializes LCD as Display ON,


Starting Page = 0 and Offset counter count up mode
when a character is displayed.

- 165 -
LCD INTERFACE
.,..
9.4.1.1 Sample Program For LCD Initialization.

. ,• ---'
; ·In it i a 1 i ze Segment driver •
,•

·---
, Eciuaters
PORTA EQU "X089
PORTS EQU "X08A
LCDCOM EQU "X0FE
LCDSTAT EQU "X0FE

LCDINIT:
DI ; Inhibit disturbance for Por~
A/8
CALL SELALL ; Select all Segment Driver.
CALL LCOBUSY ; Yait until LCD become Ready.
XRA A
OUT LCOCOM . ; Reset Address Counter.
CALL LCOBUSY
MVI A,"X38 ; Offset counter Up mode.
OUT LCDCOM ;
CALL LCOBUSY
MVI A,"X3E ; Set starting PAGE=0
OUT LCOCOM
CALL LCOBUSY
MVI A, ""X39 ; Display ON.
OUT LCDCOM ,•

LCOBUSY:,
; Uait until LCO become Ready.
IN LCDSTAT ; Get LCD status.
RLC ; Move MSB to CF.
JC LCOBUSY ; Wait if LCD is busy.
RET

SELALL:
; Select all Segment Drivers

- 166 -

,-
LCD INTERFACE

MVI A, "XFF ,•
OUT PORTA : S9h
IN PORTS ; Get current status.
ORI 03 ; Select block 9,10.
OUT - PORTS
RET
ENO

- 167 -
LCD INTERFACE ·•

9.4.2 How To Write A Character.

Writing a character on-the!LCO is performed by writing


some Bit patterns in the Display RAM of Segment Driver.

Basic sequence of writing a character on the·LCO is as


follows.

1. Select LCD Block(Segment Driver) which you want to PUT a


character.
2. Set the Offset counter mode.(Usually Up mode)
3. Set the Address where 1st byte should be written.
4. Write the Bit pattern.
S. Set Starting PAGE counter
6. Insure Display ON.

rf. Next sample program.

- 168 -

,,.-
LCD INTERFACE ..
9.4.2.1
- . .
Sample Program Of Writing A Character On The LCD.

This Sample program shows how to write a character on


the LCD. This routine updates the pointers which is used by
System ROM, ROM #0, to maintain the system circumstance.

; Sample program to write a character on LCD.


; This program performs same function as the ·following BASIC
; program •

';10 LOCATE 0,0
; 20 PRINT "A"
30 END
CSRY EQU ""XF3ES ; Cursor Y position
• (1 to 8)
CSRX EQU ""XF3E6 '; Cursor X position
• (1 to 40)
LCTEY EQU "'XFEB9 ;' Character Y Position
• (0 to 7)
LCTEX EQU ""XFEBA ;' Character X Position
(0 to 39)
PORTA EQU ""XB9 ; Segment Driver Select
; Port. •
PORTS EQU ""XBA ; ditto
LCOCOM EQU "'XFE ; LCD command Port.
LCDSTAT EQU "'XFE ; LCD Status Port.
LCOIO EQU ""XFF ; LCD data I/0 Port.
ORG ""XF000 ; 614400

LOCATE:
; LOCATE 0,0
LXI H, ""X0101 ; To set cursor position

• (0,0)
SHLO CSRY •
LXI H, ""X0000 '
SHLO LCTEY

PREP:
;-- Select Block 1 to write (1,1)
DI ; Inhibit disturbance for
; Port A/B of 81C55.
; You need not do DI as
; far as no one

- 169 -
r
LCD INTERFACE
"
; changes the data port of
; 81CSS. You have to consi~er
; other INT routines.
MVI A,"X01

OUT PORTA ,•,• Select
-· Block 1
IN PORTS ; Get current status.
ANI "811111100 ; Deselect Block 9/10.
OUT PORTS ••
CALL LCDBUSY ; Wait until LCD become ready.
. MVI
OUT
A,0
LCDCOM
; Page 0,offset 0.
,•
CALL LCOBUSY ,•
MVI A,"800110010 ; Offset counter Up mode.
OUT LCOCOM
CHROUT:
LXI H,FONTA ; Get start Address of Font A.
MVI C,"X06 ; Set Font size.

WRITE:
,•
; Write data to Display RAM of LCD
,•
; ENTRY: CHLJ = Font start address.
; CCJ ·= Length of Font.
CALL LCDBUSY ; Wait until LCD become Ready.
MOV A,M ; Get font Pattern to send.
OUT LCOIO : Write to Display RAM of LCD.
INX H ; Up date PTR.
OCR C ; Bump Counter.
JNZ WRITE ; To send next pattern.
; Offset counter is Auto
; increment Mode, so ~e don't
; care about OFFSET counter.
LXI H,CSRX ; Up date Cursor PTR.
INR M ; No check for end of line in
; this program.
LXI - H,LCTEY
INR M

;---- Set starting page--------


MVI A,AX0FF; Select all Block.
OUT PORTA
IN PORTS

- 170 -
LCD INTERFACE
...
ORI "'800000011
our· PORTB
CALL LCOBUSY • Wait unti 1 LCD become Ready •
MVI A, "'X3F. ,,••
.• St~rting page 0 •
OUT LCOCOM
MVI A,"X00111001 •• Insure display ON •
OUT LCOCOM
EI
RET

LCOBUSY:
IN LCOSTAT ,• Get LCD status •
RLC •• Move msb to CF •
JC LCOBUSY
RET

FONTA: OB "'X3C, ""X12, "'X11 ,• Font data for I A I

OB "'X12,""X3C,"'X00
ENO

- 171 -
LCD INT-ERFACE
t
9.4.3 How To Set/reset A Dot On The LCD.

TheSample program shown blow explains how to


set/re5et dot on the LCD. It does same function as the
a
following·BASIC program.

100 CLS
110 FOR Y=9 TO 22
120 FOR X=60 TO 80
130 PSET<X,Y)
140 NEXT X
150 NEXT Y
160'
170 FOR Y=14 TO 18
180 FOR X=64 TO 76
190 PRESETCX,Y)
200 NEXT X
210 NEXT Y
220 ENO

9.4.3.1 Sample Program For SET/RESET Dot •

,•
; Sample program for SET/RESET a Dot •
,•

PORTA EQU "XB9 ,• LCD block select •


PORTS EQU "XBA ,• I I
LCDCOM EQU ""XFE •• LCD command •
LCDSTAT EQU LCDCOM • LCD status •
••, LCD data I/0.
LCOIO EQU ""XFF

PSET:
DI •, Disable a 11 interrupt
,• to keep correct block
select.
XRA A ,• To set SET flag.
STA SR ,• Set/Reset Flag •

- 172 -
/
LCD INTERFACE
..
LXI B., "X140E ..., CBJ=20 X count,CCJ=14 y
count.
LXI H,"'X0A09 ,• CHJ=X Position,CLJ= Y
Position.
PSETl:
PUSH H ~.,, Save CX,Y) Position.
PUSH B • Save X,Y count •
·CALL MAIN
POP B ,• Restore X,Y count •
POP H ,• Restore X,Y position
INR L •, Advance Y position.
OCR C • Bump Y counter •
JNZ PSETl '
PRESET:
MV.I A,"XFF • To set SR Flag.
STA SR ,•' Set Unplot Flag •
LXI B,"X0C06 • CBJ=12,CCJ=06
LXI H,"'X0E00 •' <CHJ,CLJ>=<14,13>
PRESET1: '
PUSH H • Save X,Y Position.
PUSH B ,•' Save X,Y counter •
CALL MAIN
POP B •, Restore X,Y counter.
POP H ,• Restore X,Y position.
INR L • Advance Y position.
OCR C •' Bump Y counter •
JNZ PRESET! '
RET
MAIN:

'•, CHJ = X position
,• CLJ = y Position
,• CBJ = X count
,• CCJ = y count
PUSH H • Save X.Y Position.
CALL DOT ,•' Plot/Unplot a dot at CX,Y)
POP H • Retrieve Position.
INR H •' Advance X POSITION.
OCR B ',• Bump X counter •
JNZ MAIN ,•
RET
DOT:
CALL LMAIN
LOA SR •, Get SR flag.
ORA A •, See if set/reset?
JNZ RESET ,• Branch if Reset.
MOV A,E ,• Get MASK pattern .

- 173 -
LCD INTERFACE
..
ORA D a •f CAJ = data to write.
JMP DISP
RESET:
MOV A,E ,• Get Mask Pattern.
XRI ""XFF ,• Reverse MSK pattern •
ANA D •, CAJ = data to write.

DISP:
MOV D,A
CALL WRITE
DI
MVI A, ""XFF ,• Select all Block.
OUT PORTA
IN PORTS
ORI ""800000011
OUT PORTS
CALL LCDBUSY ,• See if Led Busy.
MVI A,"'800111111 • Starting Page 0
OUT LCDCOM '
CALL LCDBUSY
MVI A,'"'800111001 ,• Display ON.
OUT LCDCOM
EI
RET

LMAIN:
• ENTRY: CHJ·= X po!lition in Block-1
'• CLJ = y Position in Block-1
'• Reg:
'
PUSH H ,• Save X,Y position.
PUSH H
CALL SEL2 • Select Blocl<-2.
CALL SETADR ,'• Set Address of Display RAM.
CALL READ ,• Read· the LCD.
POP H ,• Retrieve X,Y position.
CALL GETMSK ,• Get Mask Pattern.
POP H ,• Retrieve CX,Y> Position
CALL SETADR
RET
WRITE:
,• Fune: Output CODATJ to LCD.
,•
,• Reg: A and Flags.
CALL LCOBUSY
MOV A,D ,• Get Data to r..1rite •

- 174 -
LCD INTERFACE·

OUT LCOIO ·•
NOP ; Must be EI at final.
RET
READ:
-l
Entry: Non
Exit: COJ = Current Data in Display RAM.
Reg: A,O and Flags.
CALL LCOBUSY ; Wait until LCD become Ready.
IN LCOIO ; Dummy Read.You must do this
to .
; get correct data.
CALL LCOBUSY •
IN LCOIO ;' Get Valid Data.
MOV O,A ; Save it.
RET
GETMSK:
; Entry: CLJ ·= ·y Position
,•
; Exit: CEJ = Mask Pattern •
,•
; Reg~ A,L,E and Flags.
MOV A,L ; Get Y position.
ANI "B00000111 ,•
MOV L,A ; Set counter.
.MVI A,"B80
MSK1:
RLC
OCR L ; Bump counter.
JP MSK1 ; Branch if not finished.
MOV E,A ; Save Mask pattern.
RET
SETAOR:

,'• ENTRY: CHJ =X Position on Block-2
,•
,•
CLJ = Position
y on Block-2
,• FUNC: Set Address

,'• Register:
,• A,H,L and Flags •
MOV A,L Get Y position.

- 175 -

LCD INTERFACE ...
RAL ; ; Mbve Bi t4/3 to Bi t7 /6.
RAL
RAL
ANI "'81100'e000 ; Get page.
ORA H ; CAJ = Page and OFFSET.
MOV L,A "' ; Save it.
CALL LCOBUSY ; Wait until LCD become Ready.
MOV A,L ; Retrieve Address.
OUT LCOCOM
RET
LCOBUSY:
; Entry: Non
,•
• Fune: Wait unti 1 LCD become Ready.
,'•
,• Exit: Non
,•
• Reg: A and Flags~
,•'
IN LCDSTAT ; Get LCO status.
RLC ; Set Busy FLG to CF.
JC LCOBUSY ; Wait if LCD is BUSY.
RET
SEL2:
; Select Block-2
;
; Reg: A and Flags •

'
OI
MVI A,"'800000010 ; Select Block-2
OUT PORTA
IN PORTS
ANI "'811111100
OUT PORTS
RET

SR: DB 00 ; Set/Reset flag.


; 0=set/FF=r~set.
ENO

- 176 -
LCD INTERFACE

· 9.4.4 How To Define A Characte·r

This section describes how to define the User


DefinabJe characters in PC-8201A.- And how to store them 1n a
portion of RAM where ROM #0 can use this your new Fonts. In
this section, BASIC command will be used to do some operation.

9.4.4.1 Structure Of Character And How To Define It.

One character consists of 6 * 8 dots. Vertical 8 dots


is handled by a byte. So in order to define a character, you
must define Sequential 6 bytes of data. The data AX3C, AX12,
AX11, AX12, AX3C, AX00 define "A" as follows.

- 177 -
LCD INTERFACE •'

08 <"'X3C, "'X12, "'Xif~ "'X12, "'X3C, "X3C, "'X00 >


: CG pattern for- 'A'

DATA Pattern Font pattern


0 1 2 · 34 s 0 1 2 3 4 S
lsb +---+---+---+---+---+---+ +---+---+---+---+---+---+
0 : 0 : 0 1 I 0 : 0 : 0
+---+---+---+---+---+---+
: * :
+---+---+---+---+---+---+
1 : 0 I 1 I 0: 1·: 0 I 0 I
+---+---+---+---+---+---+
* : : * :
+---+---+---+---+---+---+
2 : 1 : 0 I 0 : 0 I 1 I 0 : * : * :
+---+---+---+---+---+---+ +---+---+---+---+---+---+
3 : 1 : 0 l 0 : ·0 1 0 : * : : : : * : :
+---+---+---+---+---+---+ +---+---+---+---+---+---+
4 : 1 1 1 I 1 I 1 : * : * : * : * : * :
+---+---+---+---+---+---+ +---+---+---+---+---+---+
s 1 : 0 : 0 I 0 I 1 : 0
+---+----+---+----+---+---+
: * : -: * :
+---+---+---+---+---+--+
6 1 I 0 : * : ·: * :
+---+---+---+---+---·+---+ +---+--~+---+-~-+---+---+
7 I 0 I 0 : 0 I 0 I 0 I 0 . I
I

msb +---+---+---+---+---+--+ +---+---+---+---+---+---+

Fig 9.4

- 178 -
LCD INTERFACE
-~ -~
9.4.5 How To Store The Your Own CG

This section explains how to store USER CG in to RAM


which also can be used by ROM #0. ,t

Assume that you have to define Fonts as described in


the previous section. Each Font consists of 6 bytes. Font
Data has been BSAVEed in the RAM file named "FONT.CO", uhose
start address is AXYYZZ.

You can make "FONT.CO" in the following sequence.


1. Reserve area for "fONT.CO" by CLEAR command in BASIC.

CLEAR <length>, <startaddress>


2. Load "FONT.CO" into RAM

BLOAO "FONT"

3. Register the top address of the CG.


POKE A065216,<Start Address (High byte))
POKE A065215,<Start Address (Low byte))

After this sequence, ROM #0, for instance, BASIC, can use the
new Defined CG.

- 179 -
,,•·

LCD INT~RFACE
..•
9.S AVAILABLE SYSTEM WORK AREA

This section explains· how t6 use the system Character


Generator and how to use the available System work area.

9.S.1 How To Use The CG In System ROM.

You might want to use the CG of ROM #0 instead of


making new CG by yourself. In such a case, this Section will
help you.

The Character Generator of characters whose code 1s


from AX20 to AX7E, are stored in the highest portion of the
ROM i0, from AX7887 to AX7837. Each Character consists of 5
bytes: The sample program shown blow explains how to get the
character pattern and how to expand it into the standard
shap•, 6 * 8 pixels. Assume that this program is written to
be stored as the CO File in the RAM files and will be executed
with ROM #0 •

•,
; ENTRY CAJ = character Code (AX20 to AX7E)
,•
EXPAND:
SUI A,AX20 ,•
MOV C,A ,..
ADO C ; *2
ADO A ; *4
ADO C
MOV C,A ; CCJ offset from base of CG.
MVI B,"'X00 ,•
LXI H,CGAOR
DAO B
LXI 8,TEMP
MVI O, "'XS ; Set font data length.
NEXT:
MOV A,M ; Get Font data.
STAX 8
INX H
INX B
OCR D

- 180 -
LCD INTERFACE ...
··--•
JNZ NEXT
ORA A
STA TEMP+S
RET
. -...i

- 181 -
LCD INTERFACE ··!

-··'
9.5.2 VRAM AREA IN SYSTEM Work Area

The area from XFBCO to XFE3F in the RAM, is reserved


for VRAM area of the LCD. ~rt is divided into 2 portions.
Each portion can be hold. the character codes displayed on the
LCD at a time. So the each portion has 320 bytes. The
attribute data is not saved in this.area. Only the character
code is stored.
1st "'XFBC0-"'XFCFF ; Keep previous Page
; in TELCOM.
2nd "'XFD00-"XFE3F ; Current Displayed
; character is Saved.

The character code of the character displayed at the


location (1,1) on the LCD display is stored at "'XF000, and the
code of the character at (2,1) is stored at "'XFBC1 , and so
on. So the code of the left-lowest character, (40,8) is
stored at "XFC3F. This.rule is used in the standard program
in ROM #0. For instance, BASIC, TEXT and TELCOM use that area
like a VRAM in the traditional disk top personal computer.
The menu screen also utilize that area. But You can use this
area as you like. The data in this area does not effect the
information on the LCD display, as far as you use your o~n
display routine.

•.

"'.' 182 -
LCD INTERFACE

.. .
9.5.3 Reverse The Attribute Of The Specified Area,

ROM #0 has the Reverse Attribute Table in Work Area.

Th~ at~ribute ~ata-is ~ept i~ the area from AXFA60 to


AXFA87, · Each bit represents the each character Box on LCD.
(Therefore only 40 bytes can be handle the attribute of whole
LCD screen.) When the bit is off (0), it shows that the
character Box is displayed in normal mode. And the bit is
turned on, 1, that character Box is displayed in Reverse mode,
The relation between the Attribute bit and Character Box is
shown blow. The relation of the reverse attribute bit and
each character box is as follows.

+---------------------------------------------+
:c 1,1):( 2,1)l( 3,1): : <39, 1 ) : C40 , 1 >:
+--------------------------------------------+
:< 1,2):( 2,2):( 3,2): : <39 , 1 ) : <40 , 1 ) :
+--------------------------------------------+

+--------------------------------------------+
:c 1,8)1( 2,8)1( 3,8): : <39 , 8 >I <40 , 8 > :
+--------~-----------------------------+
AXFA60 Bit0 (01,1)
Bit1 (02,1)
Bit2 (03,1)
Bit3 (04,1)
Bit4 (05,1)
BitS (06,1)
Bit6 (07,1)
Bit? (08,1)
AXFA61 Bit0 (09,1)
Bit1 (10,1)
I
. I

AXFA87 Bit0 (33,8)


Bit1 (34,8)
Bit2 (35,8)
Bit3 (36,8)
Bit4 (37,8)
Bit5 (38,8)
Bit6 (39,8)
Bit? (40,8)

- 183 -
•,:.;, ;.,:·
'

--~
·- -
- .. -·
:. -:.

....

CHAPTER 10
KEYBOARD INTERFACE

10 • 1 THE KEYBOARD MATRIX·-

The Keyboard matrix of PC-8201A is as follows.

i--?A.1
l
·i-------·'----f80
Fig 10.1

- 184 -
KEYBOARD INTERFACE
.. J.
The abbreviation PAn (PA7, PA6, ••• , PA0) and PBn
means the bit of· PORT A and B of 81CSS. Please refer to the
follo~ing sections about I/O ports. And also, KDn (K07, KO6
•• , KD0) represents the bit of the KEYIN, Input port for the
Keyboard. -' 4

Note: •;• means <SHIFTED CODE>/ <UNSHIFTED CODE)

- 185 -
KEYBOARD INTERFACE
f
10.1.1 I/0 Port For Keyboard

10.1.2 KEYBOARD STROBE----- PART A/8 Of 81CSS

msb 7 6 s 4 3 2 1 0 lsb
+---+---+---+---+---+---+---+---+
:KS7lKS6:KSSlKS4:KS3:KS2lKS1:KS0: OUT AXB9
+-------------------------------+
: X: X: X: X: X : X: X :KSS: OUT AXBA
+-------------------------------+
KSS ••. KS0 KEYBOARD Strobe
0 = Strobe OFF
1 = Strobe ON

- 186 -
KEYBOARD INTERFACE .t

10.1.3 KEVIN ----- Read Keyboard Data

. . "
.msb 7 6 s4 3 2 1 0 1sb
.

+---+---+---+---+---+---+---+---+
:KD7lKD6:KDSlKD4:KD3:KD2lKD1:KD0: IN AXEB
+---+---+---+---+---+---+---+---+

KD7 • • • KD0 ---- Keyboard data


0 = Depressed
1 = Not depressed

Read the strobed column of the keyboard. Please refer


to KEY MATRIX shown before to understand the relation between
KDn and Key on the key board.

- 187 -
KEYBOARD INTERFACE

10.1.4 Keyboard Scanning

Key scan must be per-for-med


- ... by software. It can be
done by the interrupt, RST 7.5. The RST 7.5 Pin of 80C55 is
connected to the TP PinCNo.10) of calendar- clock CuPO1990).
So that interrupt occurs every 4 msec in the standard system.

- 188 -
KEYBOARD INTERFACE

10.2
,.
SOFT WARE FOR KEYBOARD OPERATION.

10.2.1 How To Read The Keyboa~d

Basie Keyboard read se~uenee is as follows.

1. Turn on the strobe pulse to the desired column you want to


read.
2. Read the column from KYIN port.

3. Strobe off

The following Sample program shows how to read the Keyboard in


detail.

- 189 -
KEYBOARD INTERFACE
. '
10.2.1.1 Sample Program Reading Keyboard.

Following Sample program read the every column and


save the data into the KYBUF(Keyboard Buffer) •

,•
; Read CURRENT KEY BOARD STATUS •
,•
; Note: Make sure Keyboard strobe is
• not disturbed while reading the key board •
,'• You have to care of the other interrupts •
,•
; Equator
PORTA EQU "X89 ; Keyboard Strobe Port
PORTS EQU "XBA • ditto
KEVIN EQU "XES '; Keyboard data Port.

ORG "XF000
REAOKEY:
LXI B,KYOATA ; Get PTR for buffer.
MVI A,"XFF ; Disable normal key strobe
OUT PORTA ,•
IN PORTS ; Get PortB Status.
ANI "XFE ; SET B0=0ff.
OUT PORTS ; Activate Strobe for
,• Special key •
IN KEYIN ; Read keyboard.
STAX B ; Save Data.
IN PORTS ; Get St8tue of Port B.
ORI "X01 ; Set B0=0n.
OUT PORTS ; Strob9 off.
MVI A,"B11111110
NOMAL:
INX B ; Prepare PTR for key Buffer
; for next data.
OUT PORTA ; Strobe On
MOV D,A
IN KEYIN ; Get data.
STAX B ; Store it.
MVI A,"XFF
OUT PORTA ; Strobe off.
MOV A,D ; Retrieve strobe data.
RLC ; Strobe for next column.

- 190 -
KEYBOAROCE
1
.... ....
.
• JC NOMAL
RET ; All done return to caller.


·- ,• PB0
' OS ·1 column
OS 1 ,• PA0 ditto
OS 1 • PA1 ditto
OS 1 '• PA2 ditto
OS 1 •' PA3 ditto
OS 1 '• PA4 ditto
OS 1 •' PAS ditto
OS 1 '• PA6 ditto
OS 1 ,•' PA7 ditto
•, Be careful that
•, Bit OFF means key
• is depressed •
'
SNO

- 191 -
. ~

CHAPTER 11
CMT INTERFACE

The physical interface of the CMT is described in this


chapter. You can find how to control the Motor of the CMT,
ho~ to write a data to the CMT and how to read a data from
CMT.

There is no description about file ·record format of


PC-8201A. If you want the information about it, please refer
to another technical manual about PC-8201A, which has already
been released by NEC HE in Chicago.

- 192 -
CMT INTERFACE
'l

11.1 HARDWARE FOR CMT

PC-8201A has the CMT interface


~
for reading/writing
data with Audio Cassette.

Reading/writing data with CMT is done via SID Pin ,SOD


Pin of CPU(80C85). And Motor is controlled by SCP (System
Control Port,AX90). The on-bit, Logical High, is represented
by 2400Hz wave (called MARK) and the off-bit, Logical Low, is
1200Hz wave (called SPACE). So the Baud Rate of the CMT can
be up to 1200 bps, bit per second. ( System ROM, ROM #0 Uses
600 bps to maintain the compatibility with PC-8001A.)

- 193 -
CMT INTERFACE

11.1.1 Writing Operation.

While S00 is high, MARK is put out to MIC and TxC.


Otherwise, SPACE is put out. Refer the next illustration.

SIO
high +-------+ I
I
+-------+ +--------
low +-------+ +-------+
I
I

MIC/TxC :< MARK>:<SPACE>:<MARK >:<SPACE>:MARK


Fig 11.1

- 194 -
CMT INTERFACE

11.1.2 Reading Operation.

Input wave from EAR Pin' is~~eformed to Square wave and


sent to SID Pin of 80C8S as shown olow. The input wave is
inverted on the way to SID Pin from EAR Pin. In reading
operation, the electric high/low. level has no meaning. The
pulse frequency indicate whether high or low of the data. The
frequency, 2400Hz means logical high ,and the frequency,
1200Hz means low.

EAR----- :<--MARK--->:<--- SPACE----->:


-+ +-+ +-+ +-+ +--+ +--+ +--+ +---
SDI----
+-+ +-+ +-+ +-+ +--+ +--+ +--+
2400Hz 1200Hz
Fig 11.2

- 195
CMT INTERFACE

11.1.3 Baud Rate Beneration.

Baud rate is Generated by software timing routine. In


• writing operation, the bit data r.or SOD Pin is set and it is
held during the proper duration by the software wait-routine.
On reading, a bit data is read in proper interval which i s ,
controlled by software. Refer to the following section ·about
the software. ·

- 196 -
CMT INTERFACE
-...--.;
11.1.4 I/0 Port For CMT

.. 11.1.4.1 SCP---- SYSTEM CONTROL PORT

I/0 Address and Data Pattern

msb 7 6 s 4 3 2 - 0 · 1sb
+----+-~--+----+----+------+--------+
: XX : XX: XX : XX :REMOTE: XXXXXX : OUT "'X90
+----+----+----+----+-----+--------+
REMOTE CMT Motor control.
0 = CMT Motor OFF
1 = CMT Motor ON

Description:
The current status of this por-t is saved at
SYSSTAT("'XFE44), so you have to update this area when
you want to change the statl.J!S of this port.

11.1.4.2 PPI 81CSS Command Set

I/0 Address and Data Pattern

msb 7 6· S 4 3 2 1 0 lsb
+---+---+---+---+---+---+---+---+
lTM2lTM1: 0 : 0 : ? : ? : 1 : 1 : OUT "XB8
+---+---+---+---+---+---+---+---+

TM2/1 Timer Command for PPI

- 19'] -

,,.
CMT INTERFACE:

TM2 TM1
0 0 NOP
0 1 Stop
1 0 --- Stop after Terminal Count
1 1 Start-J

- 198
CMT INTERFACE
......
11.2 SOFTWARE FOR CMT

11.2.1 CMT MOTOR CONTROL ....

CMT Motor on/off is simply performed by having access


to the I/0 PORT, SCP (System Control Port; "'X90). Output to
SCP with on at the bit 3 starts the CMT Motor, and with off at
bit 3 stops it.
Please make sure to update SYSSTATCXFE44) in work Area •

,•
• Turn on the motor •
,•'
CMTON:
LOA "'XFE44 . ,• Get SCP port status •
ANI "'B11110111 • See if Motor ON?
RNZ '• then r"eturn •
ORI "B00001000 ,•' Bit 4 on •
OUT SCP • Turn on Motor •
STA "'XFE44 '• Up-date Sep status •
RET '
'•; .. Turn off CMT Motor •

'
CMTOFF:
LOA "'XFE44 ,• Get SCP Status •
ANI "'811110111 ,• Bit 4 OFF.
OUT SCP • Turn off Motor •
STA "'XFE44 ,•' Up-date SCP status •
RET

- 199 -
CMT INTERFACE
_,.; _,..,
i1.2.2 Baud Rate Generati~n

~. Baud Rate must be gener~ted- by software timing


routine. The CPU uses 2.4576MHz clock, so the time of 1 bit
output/input should be counted with this clock. The sequence
of the counting operation is shown blow.

+-----------+-----------------+
: BAUD RATE: NUMBER OF STATE:
: for 1 Bit
+-----------+-----------------+
75 bps : 32448
+-----------------------------+
150 16224
+-----------------------------+
300 8112
+-----------------------------+
600 4056
+-----------+--------------.--+
1200 2028
+-----------+-----------------+
Fig 11.3

- 200 -
CMT INTERFACE
.'!' p-,
11.2.3 Write A Data To The CMT

Writing a data to the CMT is performed by controlling


SOD pin. Following sample program~illustrates how to write a
byte to the CMT.

Sample Program for writing data to the CMT

Write a byte to the CMT,the lowest routine.


Assumption:
CMT Motor rotating regularly and CALLED
, Interrupt disable.
,•
; INPUT: CAJ = Data to be send •
,•
; OUTPUT : Non •
,•
; BAUD Rate= 600 bps
,•
WRITE:
MOV 8,A ; 4: Save data.
MVI A,"'X50 ; 7: Write start bit.
SIM ; 4:
CALL HOLD ,• 18: Wait 4043 State •
IN PORTC ; . 10: Dummy to adjust timing.
MOV C,08 •, 4: Set data length in bit •
BYTEO:
MOV A,B • 4: Retrieve data •
RLC •' 4: Set a bit in CF •
MOV B,A '• 4: Save data •
MVI A,"'XD0 ;' 7 =· To send MARK.
JC SITO ;10/7: Branch if HIGH.
MVI A,"'X50 •
• 7: To send SPACE •
SITO:
SIM ; 4:
CALL HOLD ; 18: Wait 4018 state.
OCR C ; 4: Bump counter.
JNZ BYTEO ;10/7: To send next bit.
MVI A,"X00 ; 4:· To send stop bit.
RET ; 10: It is responsible to
; : CALLER Routine for
; : making
; : an adequate
: : length of the stop
; bits.

- 201 -
CMT INTERFACE

; HOLD1 gives
...
,• 24 * CHLJ + 7 (+18>
; states delay. (+18) means "CALL" instruction Status.
; So HOLD giv 7 s 4043 states delay including "CALL" of Caller.
-4 • •
,

HOLD:
..... .~

LXI H,167 ; 10: For 1 BIT (6008aud)


HOL01:
DCX H ; 6:
MOV A,L : 4:
ORA H ; 4:
-JNZ HOL01 ;10/7:
RET ; 10:

- 202 -
. CMT INTERFACE
.. ,
11.2.4 Reading A Data From The CMT

Following sample progr~m s~owe how to read a byte form


CMT •

,•
; Sample Program for Reading a BYTE.
,• Assume Called with Interrupt disable •
READ:
CALL BIT! • 10: Search for start
JC READ '
;10/7: Wait unti 1 Start bit
• •• has come •
LXI H,·???? ,•' 10:
CALL HOLD1
MVI C,8 • 7: Read 8 BIT.
BYTE!: '
CALL BITI • 18:
MCV' A,B ,
•' 4:
RLC ,• 4: Move CF to Bit-0.
MOV B,A ,• 4:
OCR C ,• 4: Bump counter •
JNZ BYTE! ;10/7: Read next BIT.
RET . ,• 10: No check for Stop bit.
,•
; Get a BIT .
,•
; EXIT: CF= 1 if MARK.
,• CF= 0 if SPACE •
,•
BIT!:
CALL SYNC ,• 18:
MOV A,D ,• 4: Get counter •
CPI 16 ,• 7: See whether MARK
,• •• or SPACE •
,• •• If MARK then CF=l,
•, •• else CF=0 •
PUSH PSW 12: Save CF.
LXI H,??? • 10: Assume MARK.
JC BITI1 '
;10/7: Good assumption.
LXI H,??? ,• 10:
BITI1:
CALL HOLD! ,• 18:
POP PSU •, 10:

- 203 -
CMT INTERFACE

'· RET ··"' : .:f 1~:



:' Calculate Pulse Duration •

. ' ;' EXIT: COJ = loop count in this ~outine •

'
SYNC:
MVI 0,36 • 7: Reset counter-_ •
•' •• Mar-gin i!I about 10%.
RIM '• 4:
ANI "X80 '• 7: Isolate SIO bit •
MOV E,A ,•' 4:Save it •
SYNCl:
RIM ,• 4: Get Current status •
"ANI "X80 ,• 7: Isolate SID bit •
CMP E ., 4: Same status?
JZ SYNCl :10/7: then wait.
SYNC2:
RIM • 4: Get current SIO •
OCR 0 •' 4: Bump counter •
JZ SYNC ';10/7: Too long,Restar-t.
ANI "X80 • 7: Isolate SID •
CMP E ',• 4:
JNZ SYNC2 ;10/7:
MOV A,D. ,• 4: Get result •
CPI 11 •
•• 7:•• Too shor-t?C392 9tate,
mar-gin 20%)
JNC SYNC '
;10.17: then restart.
RET ,• 10:

- 204 -
• _.J

CHAPTER 12
SERIAL INTERFACE

PC-8201A has 3 channels of Serial Interface. They are


used by RS-232C, SIO1, SIO2. The difference bet~een SIO1 and
SIO2 is only the shape of connector.

This chapter describes how to control the Serial Port.

- 205 -
...,_ ..., .,

SERIAL INTERFACE

12.1 HARDWARE OF SERIAL INTERFACE~ -4

UARTC6402) and PPIC81C55) control the Serial


Interface. 1
Since they are shared by 3 channels, Only one
channel is available at a time. Refer to the •pc-8201A USER'S
GUIDE• about capacity of the hard~are.

-- -2~6 -
SERIAL INTERFACE

12.1.1 I/0 Port ·?

12.1.1.1 Channel Select -- (System~Control Port)

I/0 Address and Data Pattern


msb 7 6 5 -- 0
+----+----+------------+
:SRI2:SRI1l XXXXXXXXXX: OUT "'X90
+----+----+------------+
SRI2/1 Serial Interface Select.
SRI2 SRI1 User
0 0 Not Used
0 1 SI02 (Disk Driver)
1 0 SI01
1 .1 RS-232C

Note: Current status of this port is saved


in SYSSTAT C"'XFE44) by System ROM.

- 207 -
SERIAL INTERFACE

"-i
12.1.1.2 UART Mode Control

-~
msb 7 - S 4 3 1
·:+-------+----+----+----+---+---+
xxxxx lCLS2:CLS1: PI :EPE:sas: OUT "XD8
+-------+----+----+----+---+---+
S8S Stop Bit Select
0 = 1 bit
1 = 2 bits 00
(*) When Data length is 5 bits,
Stop Bits is 1.5 bit.
EPE Even Parity Enable
0 = Odd Parity
1 = Even Parity
(Meaningless if Pl= 1)
PI Parity Inhibit
0 = Parity Enable.
1 = Parity Disable
CLS2/1 Character Length Select
"800 = 5 bits
"B01 = 6 bits
"B10 = 7 bits
"811 = 8 bits

- 208 -
SERIAL INTERFACE

-..:•1 .::t
I
12.1.1.3 UART Status Read

I/0 Address and Data Pattern


., _,_ .;.J

msb 4 3 2 1 0 lsb
+-------+----+----+----+----+------+
: XXXXX :TBRE: PE : FE l OE :dcd/dr-: IN "'XDB
+-------+----+----+----+----+------+
dcd/dr- OCO/OR on off C0=on/1=off)
OE Over--r-un Err-or- (!=Detected)
FE Framing Err-or- Cl=Detected)
P~ Parity Err-or- (!=Detected)
TBRE Transmit Buffer- Register Empty
1 = Ready to receive data to transmit.

- 209 -
I
SERIAL INTERFACE

· 12.1.1.4 UART Saud Rate <PP!' 81CSS Timer Section)

I/0 Addre"ld Data Definition


J
msb 6 54 3 2 1 0 lsb
+---+---+---+---+---+---+~--+
. :M2 :T13:T12:T11:T10:r09:T00: OUT AXBO
+---+---+---~---+---+---+---+
:T06lT05lT04lT03:T02:T01:T00: OUT AXBC
;---+---+---+---+---+---+---+

e ·Specify timer output Mode


AB00 = Single Square Wave
AB01 = Continuous Square Wave
AB10 = Single Pulse On
AB11 = Continuous Pulse

1:
set a Baud Rate use blow value.

--------+---------+-------~-+
ud Rate : AXBC ., AXBO
I

--------+---------+---------+
75 00 48
·--------+-~-------+---------+
150 . : 68 45
·--------+--------+---~-----+
300 00 42
-~-------+---------+---------+
600 00 41
--------+---------+-~-------+
1200 80 40
---------+---------+---------+
2400 40 40
---------+--------+-~-------+
2400 40 40
---------+---------+---------+
4800 20 40
----------+---------+---------+
9600 10 40
----------+---------+---------+
19200 08 40
-----------+---------+---------+
Fig 11.1

- 210 -
SERIAL INTERFACE
:-, . .,
NOTE:

It is impossible to read the current UART


status directly. ROM #0
always saves the new stat~s jn RAM when it is changed.
Refer to Chapter
12.3.

- 211 -
SERIAL INTERFACE

12.1.1.5 UART DATA I/0 Port

: I/0 Port and Data Pattern .....

msb lsb
+--+--+--+--+--+--+--+--+
:D7lD6:Ds:D4:D3:D2:D1:00: IN/OUT Axes
+--+--+--+--+--+--+--+--+

Note:
If the data length is less than 8 bits, Output
data must be right justified. Input data is right justified
by UART.

- 212 -
SERIAL INTERFACE

12.2 SOFTWARE DESCRIPTION.

, 12.2.1 How To Initialize Serial Port

The basic sequence to initialize Serial Port is as


follows.

1. Select Channel
2. Set Baud Rate.
3. Set transfer mode.

Following Sample program shows the Initialization sequence


more detailed.

The sample program listed blow explains how to


initialize serial port. This sample program Initialize
RS-232C Channel as 9600bps, even party,7 bit data length,1
stop bit and no control for Xon/Xoff,SI/SO. And it Updates
work area for ROM#0 can be use the same mode. You may skip
that portion if you want. They is no problem even if you skip
the updating the data,because ROM#0 always initialize RS-232C
Port when entering to Term mode or "OPEN "COM:"" ·of Basic
command is issued by the Mode string.

- 213 -
SERIAL INTERFACE
-~f
12.2.1.1 Sample Program ••• How To Initialize SERIAC Port

i .

; Sample Program Initialize Serial Port •


.
; Data in system area ~hich you must update.
SERMOO EQU ""XF406 ; 6 bytes for MODE string.
• ""XF406 ; Baud rate Specifier •
'• "'XF407 ; Parity Mode •
,'• "XF408 ; Word Length •
• "XF409 ; Stop bits •
'• "'XF40A ; XON/XOFF contorl •
•' "'XF408 ; -SI/SO contro 1 •
'INHDSP
INHIBIT
COMACT EQU "'XFE43 ; current user IO for
; serial port.
,• "'800 = Not used •
"'801 = SI02
,• "810 = SI01
,• "811 = RS-232C
SYSSTAT EQU "XFE44 ; SCP port status.
BAUORT EQU "XFE4A ; Baud Rate Table entry
address.
INHB.IT EQU "XFE4·1 ; 0 inhibits XONIXOFF control.
• I/0 Port Address •
'
SCP EQU "X90 ; System Control Pert.
PORTS EQU "'XBA ; RTS/OTR set port.
TIMEL EQU "XBC ; Timer Set Low.
T-IMEH EQU "XBO •, II I I High •

RTSDTR EQU "X3F ; RST/OTR data for RS-232C.


; Use "XFF for SI01/2.

INITSERI:
; ENTRY: CCJ = USER IO.
; CBJ = Baud rate specifier. ASCII Number (1 to 9)
; Same Number of "STAT" of TELCOM.
See if Serial Port is available.

LOA COMACT ; Get current user IO.

- 214 -
tf
SERIAL INTERFACE
·J
i
! .
ORA A • No one use Serial I/0?
JZ SELECT ,•' then branch.
CMP C • SAME USER?
.. JZ
·sTc
RET
SELECT ,•'
·.-,

. Th~:m branch.
Set Error.FLG.
Re~urn to caller.
'
SELECT:
; Reserve Serial Port-------
DI ; Inhibit all disturbance.
MOV A,C ; GET USER ID.
STA COMACT ; Set User ID. Be sure reset
; Use ID to @0 after all task
; finished,else the serial
; port
; can not be shared to
; another user.
RRC ; Move Bit0-1 to Bit 6-7
RRC
MOV C,A ,• Save it.
LOA SYSSTAT • Get current SCP status.
ANI "'B00111111 ',• cancel channel contro 1 •
ORA C ,
• Set new channel control
• bits •
OUT SCP •' Select channe 1 •
STA SYSSTAT ',• Update SCP status.,
·--
, Set BAUD RATE--------------

SETBAUO:
MOV A,B ,• Get BAUD RATE IO.
STA SERMODE • Update Baud rate Specifier.
SBI •1 • '• Convert to Binary Number.
RLC ,•' *2,Because table entry is
• 2 bytes •
LXI H,TIMTBL •'
MOV C,B ,'• CCJ = Offset
MVI B,0
DAD B
SHLO BAUORT • Save entry point for
,•'
Music routine.
,•Music routine in ROM #0
•, destroy temporary changes
the timer count and
,• reinitializes it with
,• this entry data after
• finish •
.
,' Refer Chapter 12.3
MOV A,M ,• Get Lot..1er value.

- 215 -
SERIAL INTERFACE

OUT TIMEL •
INX H '
MOV A,M ; Get Higher Value.
OUT TIMEH
MVI A,"XC3 .• ; -l'o 9tart timer.
OUT ""X88 ; Uee this value to
; etart Timer •.
~

; SET TRANSFER MOOE.


MOOE:
IN PORTS ,•
ANI RTSOTR •, IF 232C RTSOTR=AX3F to
,•activate RtS/DTR,
,• else "XFF to unactivate •
OUT PORTB
IN "XCS ,• Dummy read to clear
,• Receive Buffer Register •
MVI A,"800001110 ,• 7bit,Even Parity,1 stop bit.
OUT 008H • Set Mode.
'
,• Update SERMODE
LHLI ; Set PiR
MVI ; Set Parity check mode.
INX
MVI ; Set Word length.
INX
MVI ; Set Stop bit length.
INX
MVI ; Set XON/OFF control mode.
INX
MVI ; Set SI/SO control Mode.
XRA ; Set CF=0
STA ; Disable XON/XOFF control.
EI
RET
TIMTBL: DB "X00, "X48 ,• 75 bps
08 "X68,"X45 ,• 150
OB "X00, "X42 • 300
OB "X00, "X41 •,' 600
OB AX80,"X40 ,• 1200
OB "X40,"X40 ,• 2400
DB "X20,"X40 ,• 4800
OB "'X10,"X40 ,• 9600
DB "X08,"'X40 ,• 19200

- 216 -
SERIAL INTERFACE
....-,
12.2.2 SEND A Data To T~e Serial Port

~ The sample program shown blo~ describes how to send


data to the serial port. It performs no XON/NOFF and no SI/SO
contro 1.

; SEND A data to the serial port


,•
: ENTRY: CCJ = DATA TO BE SEND
,•

WRITE:
IN "'XD8 ; Get UART status.
CPI "800010000 ; See if transmitter buffer
r--. ; register Empty?
JZ WRITE ; Wait TBR become empty.
MOV A,C ; Get character to send •
OUT ....XC8 ; Send it to the serial port.
RET

- 217 -
I
SERIAL INTERFACE
--f
12.2.3 Read A Data From Serial Port.

·• ~ Sample program shown blow~explains how to read data


from serial port by RST6.5. This sample only read data form
serial port with RST6.5,no XON/XOFF and no SI/SO control is
performed.

:** Read a data from Serial Port.


;Read a data By RST6.5

ORG "'X3C ,• Entry point of RST6.5


RST65: DI ~-,:-
~~,.
JMP READ &~
-r~
ti
r
ORG ???? t[~

READ: ~
PUSH H ,• Save registers. ti
PUSH D ~
PUSH B i~
PUSH PSW i
IN "'XC8 ,• Read the data
MOV L,A ,• Save it •
IN "'XD8 ,• Get error status •
ANI "'B00001110 ,• Strip error bit.
MOV H,A ,•
SHLO BUFFER
POP PSW ,• Restore Registers.
POP B
POP D
t~
POP H r
;~
EI '
~';

RET ~
l
}
BUFFER OS 1 ,• Got Data.
OS 1 ,• Error status .
~~
[
V

~
i,;

~
t
~

- 218 -
SERIAL INTERFACE

-~ ··t
12.3 AVAILABLE SYSTEM AREA.

~- You may want to-use the sy~tem area for your use. In
this section, the available work area of ROM #0 is described.
Make sure to keep the compatibility with System ROM, if you
want use this area.

Serial input Buffer from AXFE4C to AXFFC3, is reserved by


System ROM as SERIAL Input Buffer. And You can use it for
your own routine.

SERMOD saves their RS-232C mode string

This area has 6 bytes data which indicates the RS-232C


String Mode, specified by "STAT" command in TELCOM or OPEN
"COM:" command in BASIC. The contents are following.

SERMOD at AXF406 0S6 ,• RS232C String mode Buffer


"'XF406 • Baud rate specifier (1 to 9)
"'XF407 ·'• PArity Mode CN/E/0/I)
"XF408 ,•' Word length specifier ( 5 to 8)
AXF409 • Stop bit (1/2)
AXF40A •' Xon off control (X/N)
"XF408 '• SI/SO control CS/N)
'
INHIBIT Cat "XFE42>
This byte is the XON/XOFF Inhibit Flag. 0 inhibit
XON/XOFF ~ontrol ,else enabled.

COMMACT ("XFE43 Byte)

This byte indicate who is using serial port as blow.


Please reset to 0 after using the serial port,
otherwise the serial port is not available for another
user.

"X00 = No user
"X01 = SI02
AX02 = SI01
"X03 = RS-232C

- 219 -
SE~IAL. INTERFACE

CMPNT (at "XFE46) 0S1 ; Character -count in Suffer.


This byte ha!!I. the character count in Seri a 1
Buffer.
i.: . ... . ,:J

This byte indica·te last read character displacement.

UTAOR <"XFE47 Byte>


This byte indicate last written character
displacement.

BAUORT C"'XFE4A)
This points the tab 1e of the Baud rate.. Refer to the
Chapter 12.2.1.1 ·sample Program.

- 220 -
,: .... ··.~
_,.
......... -----··--

CHAPTER 13
BARCOOE READER

This chapter explains Electric specification and Basic


theory of Operation of the Barcode Reader.
The Barcode Reader program included in· the PC-8201A
Personal Application Kit assumes that operation is done uith
the HEOS-3071 ( pr-educed by HP Corp.) . ·

13.1 ELECTRIC SPECIFICATION

Refer to the "PC~8201A USER'S GUIDE" about the shape


and Pin Connection of the BAR Code i~te~face a~d elect~ic
specification.
You may connect any Bar Code Pen to this interface.
But NEC recommends the products of YHP(YOKOKAWA HP) or (MECANO
Kogyo) and it is better that the Pen has the Power switch, for
saving the electric power of the PC-8201A.
The data line of Barcode Reader is connected to the
Pin-2 of BCR. And this pin is connected to the RSTS.S of
CUP(80C85) and Port C-3 of 81C55 as sho~n blow •

. ~~B

~ G-~G-~e - - , 1?1~
5 ,...,___
7711
'Ice. Fi'i~ {3.1

- 221 -

l.·
BARCOOE REAOE.R

While the Bar-code Re.ader ~is p01.1er-ed on, PIN-2 is kept


as 101.1 1eve 1 , and RSTS.5 lS High.
BLACK BAR is represented by logical Low, SPACE BAR by
. J
High respective 1y·. .. -"

13.2 THEORY OF OPERATION


This section describes the basic sequence of the
reading data from Bar-code Reader.
1. If power- on. RSTS.5 is activated. At the fir-st point of
the RSTS.5 routine which is inter-r-upted by RSTS.5 disable
a 11 inter-r-upt.
2. Pole the Bar- Code DATA por.t. · And calculate the duration
of same status and save the status and Duration.
3. If Low level continues too long assume that Po1.1er- off and
enable
4. Decode the got.Data and transfer the data to the upper-
r-outine.

- 222 -
--
CHAPTER 14
PARALLEL INTERFACE

This chapter describes ho~ to control the


Printer Interface of the PC-8201A. It is the
Centronics compatible a 8-bit parallel interface.

14.1 HARDWARE SPECIFICATION


14.1.1 Physical Interface Of PC-8201A
. PC-8201A has the Centronics compatible
parallel interface. It uses 26-pin connector.
Refer to the PC-8201A USER'S GUIDE about the Pin
connection and ~ignal name.

14.1.2 I/0 Port For PRINTER Interface.

14.1.2.1 Port A---- Data Out Put Port For Printer.

lsb 7 6 S .4 3 2 1 0 lsb
+---+---+---+---+---+---+---+---+
:Po7:Po6:Pos:Po4:Po3:Po2:Po1:Po0: ouT Axs9
+---+---+---+---+---+---+~--+---+

- 223 -
PARALLEL INTERFACE

P07 to P00 DATA output to Pr-inter.

NOTE: This port is used by another user.


• - -'

14.1.2.2 Port C ---- BUSY,SLCT Signal Read

msb 7 6 5 4 3 2 1 0 lsb
+--+--+--+--+--+----+----+----+
:xx:xx:xx:xx:xx:susv:sLCT: xx: IN Axse
+--+--+--+--.+--+----+----+----+

BUSY 0 Pr-inter READY


1 Printer BUSY
SLCT --- 0 deselect
1 Select

14.1.2.3 SPCCSystem Control Port> --- STROBE Output


Port

msb 7 6 5 4 3 2 1 0 lsb
+--+--+----+--+--+--+--+--+
:xx:xx:PsTs:xx:xx:xx:xx:xx: ouT Ax90
+--+--+----+--+--+--+--+--+

PSTB --- 0 Strobe OFF


1 Strobe ON

- 224 -
PARALLEL INTERFACE

14.1.3 Basic Theory Of Writing A Data To Centronics

The basic sequence to write


- .... data to the
Centronics printer is as follows.
1. If Printer i9 bu9y, wait a while. Other~ise go
ahead.
2. Output a byte to the data lines and hold it.
3. Change the strobe level to low.
4. Wait a adequate duration holding the DATA.
s. A1 1 has been done, then finish else repeat from
( 1).

The timing chart illustrates the sequence.

Para 11 e 1 __ xxxxxxxxxxxxxx ________ _


DATA ->:T1:<- ->: T2 l<-
DATA
-------+
->: T3
+-------------------
:<-
STROBE +-----+

-------·--+
BUSY
-------------+ +-----
T1,T2 >= 1.0 uSec
1.0 uSec < T3 < 600uSec
Fig 14.1

Refer to the Manual Qf Printer about the


actual Duration of Tl to T3.

- 225 -
PARALLEL INTERFACE

14.2 SOFTWARE SPECIFICATION

1 ;4.2.1 How To Write A Byte To The Printer.

Tiny program shown blow explains how to send a


character to the Parallel port. That sample Program does
same function as Basic command,
LPRINT •ABCDEFGHIJ•

,•
,•
•,
600000
;-- Ec;uater
SCP EQU "'X90 ; System Control Port.
PORTA EQU "'XB9 ; Printer Data Port.
PORTC EQU "'XBB ; Printer Status Port.
SYSSTAT EQU "'XFE44 ; SPC status.

START:
LXI H,BUF ; Set PTR.
MVI C,10+2 ; Set data length.
PRINT:
IN PORTC ; Get Printer status.
ANI 6 ; Strip BUSY,SLCT bits.
XRI 2 ; See if ready.
JNZ PRINT ,• if not,then wait.
DI ; Inhibit disturb for Port A
; of 81CSS.
MOV A,M ; Get character to Print.
OUT PORTA Put data on the DATA line.
LOA SYSSTAT Get SCP status.
MOV B,A Save It.
· ORI ""800100000 Set STROBE.
OUT SCP
MOV A,B
OUT SCP
MOV 8, ""X03 ; Please set appropriate
; value for your Printer.

- 226 -
PARALLEL INTERFACE

WAIT:
OCR 8
JNZ WAIT
EI
...
.'.
INX H
.... ~
; Point to Next
OCR C
JNZ PRINT
RET
BUF: 08 'ABCDEFGHIJ'
DB 13,10
END

- 227 -

/
....

CHAPTER 15
HARDWARE

!r to another technical manual about the detail


speci~n of PC-8201A's hardware. That manual has already
been oy NECHE, Chicago. Please contact with them. In
this r, only most important data is listed up.

- 228 -
HARDWARE

15.1 SYSTEM SLOT


15.1.1 Assignment Of Signal
.. · ----. _:. ·,· -t· ...-'..:··-··. ··~ ...-i -----=;-.-......---------~~~- -
·_System Slot

S\"STc.\l SLOT

I i
Pin number I Sigr:a/ name I
Remarks
I I
1 voo +S V

2 voo +S V

3 AOO
I Adc:-ess/Oata 0
4 AC4 Addra:s/Oata 4

.5 .A.01 Address/Data 1

6 ACS Address/Data S

7 A02 Address/Cata 2

8 A06 AddressiOata 6

9 A03 Address/Data 3

10 A07 Address/Data 7

11 NC No C0nr.e~ion

12 NC No C;:nnec:io r.

13 AS Address 8

14 A12 .O..dcr ass 12


I

Fig 15.1

- 229 -
,,,.-
HAROUA'RE

...

Pin number
I Signal name

A9
I Remarks

Address 9
15

16 A13 Address 13

17 A10 Address 10

18 A14 Addresl i4

19 Al 1 Address 11

20 Ai5 I Acld:-es~ 15

21 A16
i No Conr:ec::ion

22 A18 No Connec:tion

23 A17 No Connec:ion

24 A19 f'!o C::-~ae::=:i

25 NC Ne C,nnec:ion
.
26 NC No Connec:tion

27 RO Read .,

28 WR Write
.
29 10/M 10 OR Memory

30 ALE Address Late."I Enable

31 HOLO HOLO

32 HOLOA HO LO Acknowtedge

Fig 15.2

- 23~ -
HARDWARE

·&.--·fl
-··.r~
--:4 ---'!

Pin number
I Signal name

INTR
I Remarks

INTERRUPT
33

34 INTA INTen Ackncwlec;e


I
R~----
35 RESET I ::.c. l

36 READY I READY

37 ROME RCM e:iat:le


I
38 I E E:iacle

39 BANK;:;:3 FIAM Cassette Selec: signal

40 NC No Connec:ion

41 .HAORO High Address Disable

42 LAORO Low Address Disable

43 CLJ< Clock

44 POWER RAM Protec: signal

45 GNO Ground

46 GNO Ground

47 NC No Connection

48 NC No Connection

Fig 15.3

- 231 -
HARDWARE

15.1.2 Explanation Of Pin

• 1s.1.2.1 Function Of Signal

1. Vdd COut)
If you don't use the BCD, this Pin can supply with
the current of 50mA or so.

2. A00-A07 <In/Out)
Lower 8 bits of the memory address Cor I/0 address)
appear- on the bus during the first clock cycle of a
machine cycle. It then becomes the data bus during the
other cycles.

3. A8-A15 COut)
The most significant 8 bits of the memory address or
the I/0 address. The output goes off during Hold mode,it
then becomes •H• level, because it is connected to a pull
up resister (100k Ohm). inside.

4. /RO COut/3-state)
The read control signal, 3-state during Hold mode.

5.- /WR COut/3-state)


The write control signal, 3-state during Hold
mode.

6. IO/M COut/3-stater
When this signal is •H• level and IL. level,

- 232 -

/
HARDWARE

respectively, the CPU have access to the I/0 and the


memory. 3-state during Hold mode.

f -~
7. ALE (Out/3-state)
It is used to strobe the address information
( A00-A07). 3-state during Hold mode.

8. HOLD CIn)
The CPU, upon receiving the hold request, will
relinquish the use of the bus as soon as the completion of
the current bus transfer. When the Hold is acknowledged,
the /RO, /WR, IO/M, ALE lines are 3-stated and the
A08-A015 lines are •H• level.

9• .HLDA <Out >


It indicates that the CPU has received the HOLD
request and that it will relinquish the bus in the next
clock cycle.

10 • I NTR CIn >


The general purpose interrupt. It is sampled only
during the next to the last clock cycle of an instruction
and during Hold and Halt states.

11. /INTA <Out)


It is used instead of (and has the same timing as) /RO
during the instruction cycle after an INTR is accepted.

12. RESETO (Out)


It indicates CPU is being reset. Can be used as a
system reset.

- 233 -
HAR~ARE·

13. READY Cin)

If it is •L ·, the CPU 1.,,i 11 wait an integra 1 -number of


clock. cycles for it to go •H• before completing the read
...... _. ----• ..._'-!, ..or w~j_t!t_ eye 1.e. ... ;;;i --~ ~..___ _.._ -.:.;
...

14. /ROME (Out)


The enable signal for external ROM cartridge or
general purpose. When the upper 4 bits of the I/0 address
1 s 8, it goes • L • •

4liHf38

IOIM I ~~1
Gr
1-
~
CONi;;oL
Y! I .
Tis
_A/4
IGZ
IC
Y.:
y4.
I
1
----
5.J.Ni<
d'"IJ~
,4o2D
Al3 ,a Ys ~
Ai2 Y' I Rrr
( y71
I L.c!5

Fig 15.4

15. E <Out>
It is used as a memory enable signal of the read or
urite cycle. Eis the logical OR (active high) of /RO and
/WR.

Fig 15.5

- 234 -
HARDWARE

16. /BANK 3 (Out)


The memory enable signal of external RAM cartridge.
(See next section)
I -~

17. HAORSO <IN)


If it is .H.,the memory of high address (AX8000 to
AXFFFF) in PC is disabled. (See next section)

18. LAORSO (IN>


If it is .H.,the memory of LOW address ("'X0 to "'X7FFF)
in PC is disabled. (See next section)

19. CLK (Out)


2.5MHz clock output. It is the same phase as CPU
clock.

20. POWER (Out)


It is the signal /RESET (connected to the CPU) is
reversed.

- 235 -
HARDWARE

15.1.3 DC Characteristics

-------------------~----------------------
Symbol Drive capacity (mA)
• -;00:;o;---------------4~4--=..---~--------
.
----------------------------------------
A8-A1S 4.4
/RD,/WR,IO/M
ALE,RESETO 4.4
HLOA,/INTA,CLK 2.0
E,/ROME,/BANK 3 1.1

Fig 15.6

- 236 -

,/
HARDWARE

15.1.4 AC Characteristics

··-< ---~----·
. j ·_
---- .-
~,I
.:

""'t-
.....
"Z'

-=~
2:
n
"M

I
,J

~
<'
Q,
-
:-' .z.
- .--
,. ~ ..."' - ·--
- :i- -

L-- I
~
c
'-1

i
i-
i-

i
I
I I - -I
I -I ' .... I
I
-
i'
i
I
I
I
! ~
!
'
'
- .! loo{
r.:-.... ~

:-J
f-.
I~
: I
r-~
-
..
~-~
~
1 ;'
I '
!
...
t
I
>-
<,.;

-
~
t:.:
I
~I
I.I.lo
IJ
I '
C:

~I
c::.
~ ,. I
-;
>

.
,. I .
~ ~ ..: ..: ).

~ J
.___ Q -:-
i::i I
f- ~ -< ,' ...: ....~
..;:

.... -,
:.. ~ :1oo
.:.

- ~
,-
... I
' 1
I

iI
I I

= ... ~
,_
lz
.
>-
~
...,:ilC C
0.
C)
C
I.I
Q:.
~
Q '.~
~ < < Ci:

Fig 15.7

- 237 -
HARDWARE

......
I X >< lJ I
-·~
·< ~'.

• I

- •---
·~,..·.-:'7... --- ·:· I-

.
I

.... I
' -I
~
' f
~ - ... -

_.i
II
...
f- . -- ...

I

-, I I
i

i
l-
L -- ....
,
-
I
1
i
'
,.
i'
!
•••

_
!
__.JI
-a - -·
~
1
1:!

<

c-,
-
Q

I Ji.
--- .- ~ -fr
I
I
l- i
~ I -; I
~
Q
Q --.
'
i!

i.
~

J It !'
;
- ,-, -
I

. ~ f
~ .....I, ,.,
.
.;; .:,

i ~! !
I I"'"!
~:

...-
.,., 4' I

- ,- - l
Q
i.....

t ~ f
I
: ... I
• :~ I
:;
I :: I

-· r~ ""1
I""'
I . ~ Ii , I
i

I II I I

Fis 15.8

- 238 - /
HARDWARE

-
"
--- --
I min (l\S) typ CnSl l'IIGl:( CnS, --
··-~-,..., - __..._...
------. -----~
1
ta~ l - J407

. tl..GX I t
112
.
t,u. I
I
rr2 I
i,:.u.
i
I
!
I
7i. I I
I
t~ ! 16:? I I
142
t,4~ I :r·1 I
! I
! I
t..: I i ...,- ~ II i
!
i ,. ..
tAD I I I
~

=~~ I I I
I
-.· -
-o.;

t:11) II I
I
334-
;
!
: tc: !2S I I
. ,
t~. I
I
163 .
t~CM i I

0 I
1
I
'
tw0&.
I I
I 7S I
ta. I
I
13 I I I
two I 88 I I
I
to,, Il
srs I r
I

: t:,D:v 'i ! '


! '-~?-
l
! ':ART
I
r I ....,:....,, -~:
I ~
·~:...:fY
I I H
t~--r: 1· /{0
I
I
I

t';rrl-!
I 0 I
I
I I

Fig 15.9

- 239 -
F
t HARDWARE

15.2 MEMORY CONTROL CIRCUIT


In this section, RAM #n means the chip number on the
main board.
... .I
. -,~ . .l

The memory of PC-82~1A corisists of RAM 16K and ROM 32K


bytes,and can be expanded to 48K bytes on optional RAM socket
CRAM Chip #2- i7) and to 32K bytes on user ROM socket CROM #1)
in PC.

Show the composition of memory in Fig 15.11 RAM Chip


(#0- #7) and ROM C#0- #1) is connected to the same DATA bus
and their out~uts are controlled by /CE and /BANK signal.
There are five banks of BANK #0(available ROM #0), SANK
#1(user ROM #1), STORAMCavailable RAM #0- #1 and optional RAM
#2-#3) ,BANK #2 (optional RAM #4- *7) and BANK *3 <RAM
cartridge). Show the bank cont~ol circuit in Fis 15.12 Sy
means of this, you can assign each back to the memory address
in 64K bytes area of CPU shown in Fis 15.13 and Fi9 15.10.

Address STDRAM EANK#2


r - - - - - - - - -- ~I
/\X FFi=t=. ·
RAM~l R~M~7
I\X Eeaa
Dr:F;: i
i
RAM le RAM#&
~ C0ee I

I\X BFFt= r - -J

RAM#2 RAt-'f #!"


/\~ Aa-sa_.
/\X 9FF F
I

..
RAM~3 RAM;:4 I

/\t.ieee
I

RAM address

- 240 -
HARDWARE

.Address· ··· --·- · ·•··


:- . .-

~i--·_m_,~_-RAM·-~----~·~!]~ ....... ~~;;:· 1.


Ruf,!
2.0Nl<l#l i
I
I
?.~r-1
:.~N7:r~
!
(D
,.----·-----·---------------~
•f\"y

I;
----
V' :-.-~,-

I
:~-i -----. ---··
:\~ C~2::J F.AM P.;M RAM
ffiii!:lr i :ANi<='2 i·8~Nl#3
I! I :....--- _!- - - -

,,
I
I

-----------------------
,,;-, ------ ----- --·-
·-=..i

--~~t:'.f. - •-- - ••
r Si'i:AAM -------~
~M
Siuii;:.l.1

"Th« 0 ~ Niiliffl ~:,:: !ii''!

-- -----·. ---· -------·-- ;! opi:0,-..1i iff'..:,,,r;,.

Fis 15.10

- 241 -
HARDWARE

·--.,..~-- ----~'~="J~.~--··------~·~1~;~~-----_-__
---~IQ~~,_ .. ·
.. I~ l: ~-
-.. ~ ~~~ .,- ----
l ~ I

-x
i I
11
i_-
~-, ~-
~) :,d~"i C',:
-
,., ~
= I ! i.
;it
:r. - ~-
- -··-----
71
.. ._..:J ,..
!
;

;
:
!,'__J*.
I---'-i~i ~~!,1·___.
~ 1
I
i I '-" ,
'; •-r.lt
'ill~~-=~f',
J I
: -
!
1:~~:<
g -¾~ '
:t-~<"'0:···,----
I
I
!
I I
1&: , I ~-
! ~
I
l
I 31: I I ...?-,
i
i
i
~ 1
;;
~
I
I
I ·s
:=
I
' i
:
C:
-~
I ·;:;
:
~
s
lI
(..:

• c-~;-
~--~o::::i:~,,---- !! -' • • o_ ~:1:J, •
~-~--~
------,11~ ~~ '~l
~1, ,-/ ~'fii :1"~..-----.
~-.
I-·

~ 1_ _ _:i::..·----...L....~

~------,J JJ
il
I !

Fig 15.11

- 242 -
HARDWARE

. .--.. --. -·. - 'f"


- . ..f
··:~

IAIJ'
LADRS
OIM '
~
! ',001r.Q 4-0Hl'TS-· t:.G - . - . ·-- -
,...___ Ya..,_-----~
A!la I jro rG/ . Yi-y,------~
,.
~
:,l,N K.;t I

--,----.W ~
At1

.4Z2 I1 ,1=~
2Q;----.:

•., J"'H:
.. l ,.~ :n ,
Ya I
_{___/--

_
!l't.i(;:.;-4

,&, .
ll
i.. ~,.,
I I ,·
a "I
-y,;·
i . D - - -;•.'.t(,S•-
;
i --1LJ -

--+0--1
i

,;..:..·J:<
~ ---..:.. I
i ~i,,::J?
.
I ;
. :n? --=5\:-1
:t-~:u --;--.:,___,./
'f.,./o.;~

~ank Control C;,-e.wf:

Fig 15.12

~I ' @2 '1@1·1:-;®
_~CD; I f · ©lCVt®tI I i

LAERII O I O I O I O I o/ 0 I I I '
UDR2 I O I O I O I f I l I I I O I ( I

HADRI j O I I , Io r I I I0 0 I

HADR2 I O ~ 0 I I0 0 I I I0 0

Fi9 15.13

- 243 -
r:
HAROUARE

The way of bank conversion by software control


illustrates in next section. When PC is reset, it becomes any
mode (before reset)of the composition No.1-3. But in the case
of nothing of optional RAM BANK #2- #3, it can become only
No.1 mode. If optional ROM is~ins~alled, another composition
No.4-6 are possible. Further, as it becomes the mode of 64K
bytes full RAM by optional RAM BANK #2- #3, you can use a
CP/M, etc.

·--~ - 244 -
HARDWARE

15.3 I/O ADDRESS

-f . (Address is expressed in Binary.) l


I/O address:In/Out: I/O device:Operation
-----~------------------------------------------
00000000 -:
user
V
01011111
01100000
NEC reserve
V ·.
01111111
-----------------------------------------------·
1000XXXX 0 NEC reserve CROM cartridge
: or general purpose) A decoded
: signal appears on /ROME pin.
1001XXXX 0 D-FF System Control
*Cassette Motor Control,
*Clock Command Strobe
*Printer Strobe
.,
I
*Serial I/F Select
----------------------------------------------~:
1010XXXX : 0 : O-FF l Bank Control
-----------------------------------------------·
1010XXXX I 3-S :
-Buff: Bank Status
*Bank Status
*Serial I/F Select
Status
-----------------~---------------------------
1011X000 :I/O PPI
81C55 Command/Status Resister
1011X001 0 Port A Output
*LCD Chip Select
*Printer Data
*Keyboard Scan Data
*Clock Command/Data
:------------------------

- 24S -
HARDWARE

:-----------
1011x010 0
------------------------
Port 8 Output
*LCD Chip Select
*Buzzer Control
·' *RS-232C Control
*Auto Power Off
Control
1011X011 I
------------------------
Port C Input
*Clock Data
*Printer Status
*BCR Data
*RS-232C Status
, 1011X100 0 Timer Resister-
Clower 8 bits)
*Lower 8 bits of counter-
1011X101 0
.------------------------
: Timer Resister
: (upper 8 bits)
l*Upper- 6 bits of counter
l*Mode Select
1100XXXX :I/01 UART:
6402: Data Urite/Data Read
--------------~:
1101XXXX : 0:
:-----------------------
Control
1101XXXX f I 3-S-:
I
I
I .
Buff: Input Port
I *UART Status
*Low Power Signal
~----------------------~-----------------------
1110XXXX : I : 3-S-:
Buff: Keyboard Input
-----------------------------------------------:
1111XXX0 : 0: LCOC: Command Write/Status
Read
---------------;
1111XXX1 : 0 :
:------------------------:
: Data Ur-ite/Data Read
~-----------------------------------------------
Fig 15.14

- 246 -
HARDWARE

15.3.1 Detail Information About I/0


This following is the particulars of each function.
The I/0 address is shown in the number which is used really in
· ~ system; - ~.t

15.3.1.1 Reserve Area

As this area is reserved for NEC,don't use it.

15.3.1.2 System Control

11 0 0 1 0 0 0 0: OUT AX90

7 6 5 4 3

:SELA:SELB:PSTB:TSTB:REMOTEI
----------------
REMOTE CASSETTE
------------
MOTOR CONTROL
0 motor Off
1 motor On
TSTB CLOCK COMMAND STROBE
0 Strobe Off
1 Strobe On
PSTB PRINTER STROBE
0 Strobe Off
1 Strobe On
SEL A SEL B SERIAL INTERFACE SELECT
0 0 Not used
0 1 SI02
1 0 SIOl
1 1 RS-232C

- 247 -
HARDWARE

15.3.1.3 Bank Control

:1 0 1 0 0 0 0 1l OUT ~Al 4 ~

3 2 1 · 0
---------------------------------
lHAR02lHARD1lLAOR2lLADR1l

LADR 2 LAOR 1 SELCT ADDRESS AX0 To AX7FFF


0 0 Bank #0 <ROM #0)
0 1 Bank #1 · <ROM #1)
1 0 Bank #2 <RAM #4 - #7)
i 1 Bank #3 <RAM cartridge)
HADR 2 HADR 1 SELECT ADDRESS
(AX8000 TO AXFFFF>
0 0 Standard RAM CRAM #0 - #3)
0 1 Not Used •
1 0 Bank #2 CRAM #4 - #7)
1 1 Bank #3 CRAM Cartridge)

- ·---- 248 -
HARDWARE
I

15.3.1.4 Bank Status

.! : 1 0 1 0 0 0 0 0: IN "XA0 .-4

7 6 3 2 1 0

BIT 1 BIT 0 STATUS OF ADDRESS


<"'X0 TO "X7FFF)
0 0 Bank #0 <ROM #0)
0 1 Bank #1 <ROM #1)
1 0 Bank #2 CRAM #4 - #7).
1 1 Bank #3 (RAM cartridge)
BIT 3 BIT 2 STATUS. OF ADDRESS
<"X8000 TO "XFFFF)
0 0 Standard RAM CRAM #0 - #3)
0 1 Not Used
1 0 Bank #2 <RAM #4 - #7)
1 1 Bank #3 (RAM cartridge)
BIT 7 BIT 6 STATUS OF SERIAL INTERFACE
0 0 Not used
0 1 SI02
1 0 S101
1 1 RS-232C

- 249 -
HAROUARE

15.3.1.5 PIO 81CSS Address

*Command I Status Resister


-~ . d ..
:1 0 1 1 1 0 0 0: IN/OUT Axes
*Port A output

:1 0 1 1 1 0 0 1: OUT AXB9

7 6 s 4 3 2 1 0

lPA7lPA6:PA5:PA4lPA3:PA2lPA1:PA0:

lP07:P06lP05lP04lP03:P02:P01lP01:

lKS7:KS6lKS5:KS4lKS3lKS2lKS1lKS0:

:ccK:co0:c2 :c1 :ce :

PA7 to PA0 LCD Chip Select


P07 to P00 Printer Data Port
KS7 to KS0 Keyboard
C2 to C0 Clock command Output Port·
.
CO0 Clock Data Output Port
CCK Calendar Shift Clock
0 Clock Off
1 Clock On

*Port B Output

:1 0 1 1 1 0 1 0: OUT ""XBA

- 2se -
HARDWARE

7 6 5 4 3 2 1 0
----------------------------------
:---:---: :DcD1:--: :
:RTS:DTR:BELL:APO:RD :MC:PB1:PB0:
• ---------~-----------~--~~----:---
----------------------------------
· :Kss:
----------------------------------
PB1 -- PB0 LCD Chip Select

MC MEMORY CONTROL OUTPUT


0 On
1 Off

OCO/RO OCO/RO SELECT OF THE RS-232C


0 Ring Detect
1 Data- Carrier Detect

AP0 AUTO POWER OFF OUTPUT


0 Output Off.
1 Output On
BELL BUZZER OUTPUT
0 Ring
1 Not Ring

DTR RS-232C OTR output Active Low

RTS RTS output Active Low

- 251
HARDWARE

*'Pol"'t C Input

:1 0 1 1 1 0 1 1: IN "'XBB
_..J J
5 4 3 2 1 0
.-----------------------------------
I --- : --- : I :
:osR:CTSLBCR:BUSYiSLCT:cor:
----~------------------------------
CDI Clock Data Input Port
SLCT PRINTER BUSY
0 Printer Ready
1 P,-intel"' Busy
BCR Bar Code Reade,- Data Input Port

CTS CTS Input Active Low

DSR RS-232C OSR Input Active Low

- 252 -
HARDWARE

*81CSS Timer Resister

:1 0 1 1 1 1 0 0: OUT/IN AXBC
----------------- -~. ~

7 6 5 4 3 2 1 0
---------------------------------
lTL7lTL6lTLSlTL4lTL3lTL2lTL1lTL0:

TL7 -- TL0 Timer Counter Lower 8 bit

:1 0 1 1 1 1 0 1: OUT/IN AXBO

7 6 S 4 3 2 1 0

lM2:M1:THS:TH4lTH3:TH2lTH1lTH0:

THS -- TH0 Timer Counter Upper 6 bit

M2 M1
0 0 This-mode transmits a single-
square wave which the first
half of the number of count
is high and remaining 1s low.
(Mode 0)
0 1 This mode continually transmits
a Mode 0 type square wave.
(Mode 1)
1 0 Thi9 mode transmits a L-pulse
(single pulse) during one
clock when finishing the
terminal count.
(Mode 2)
1 1 This mode c6ntinually transmits
a Mode 2 type pulse.
(Mode 3)

- 253 -
HARDWARE

15.3.1.6 UART Data I/O Port

-------------------
:1 1 0 ~ 1 0 0 0: IN1qur ?fC8
UART DATA PORT

15.3.1.7 UART Control Port

*Command Write

:1 1 0 1 1 0 0 0: our AxDs

:cLS2:CLS1lPI:EPE:ses:

SBS STOP BIT SELECT


0 Stop bit length is 1 bit
1 Stop bit length is 1 bit.
If data length is S bits,
stop bit length is 1,5 bits.
lh the other case, it is 2 bit.

EPE EVEN PARITY ENABLE


0 Odd Parity
1 Even Parity

Pl PARITY INHIBIT
0 Generate parity and check
1 Inhibit generating parity

- 254 -
HARDWARE

and check

CLS 2 CLS 1 CALENDAR LENGTH SELECT


~ ,~
. "'
0 0 Data Length s bits
0 1 Data length
. 6 bits
1 0 Data length 7 bits
1 1 Data length 8 bits

- 255 -
HARDWARE

*Status read

:1 1 0 1 1 0 0 0: IN AXO8
..i
----------------- - .....
7 4 3 2 1 0

:LPS: ITBRE:PElFE:OE:--:- /--:


:oco1 RD:

DCO/RO Data Carrier Detect/Ring Detect

0 On
1 Off

OE Overrun Error
1 Detected

FE Framing Error
1 Detected

PE Parity Error
1 Detected

TBRE Transmitter Buffer register Empty


1 ready to receive data to transmit

LPS LOW POWER SIGNAL


1 low power voltage

- 256 -
HARDWARE

15.3.1.8 Keyboard Input

:1 1 1 0 1 0 0 0: IN -.iXE8~ .

15.3.1.9 LCDC Address

* Command Write /Status Read

:1 1 1 1 1 1 1 0: IN/OUT AXFE

* Data Write/Read

:1 1 1 1 1 1 1 1: IN/OUT AXFF

- 257 -

You might also like