Sunday, April 23, 2017

Micro-KIM Tutorial: The Memory Map

Let’s revisit the Micro-KIM memory map, introduced in the third tutorial.

+-----------+
| 2K EPROM  |$1fff
| monitor   |
| program   |$1800
+-----------+
| 6532 RIOT |$17ff
| I/O, timer|
| and RAM   |$1740
+-----------+
| optional  |$173f
| I/O, timer|
| and RAM   |$1400
+-----------+
|           |$13ff
| 5K RAM    |
|           |$0000
+-----------+

Since the default kit (without any expansion) only uses the lower address bits to access 8K, memory repeats itself every 8K. You can verify this by storing and inspecting values in, for instance, addresses $0000 and $2000. Any value stored in one address will show up in the other. Although an interesting factoid, there is no reason to let Micro-KIM programs address anything outside the range $0000-$1fff.

Addresses $0000-$13ff contain 5K free RAM (another interesting factoid: the Micro-KIM actually wastes 3K of its 8K RAM chip to keep compatibility with the original KIM-1). This memory region can be used to store data and code. To verify this, while running the monitor program, use the keyboard to store and inspect values. For example, type AD followed by 0200, DA, and FF and you will see the value at this address change. Type + a few times to change the address. Then, if you later revisit this address with AD 0200, you will still see the value FF stored at this address.

The first 256 bytes of RAM with addresses $0000-$00ff are called the zero page. The 6502 microprocessor supports zero-page addressing to access this part of RAM with more compact and more efficient instructions. For example, both the following two instructions load the contents of address $0000 into register X, but the first uses just 2 bytes rather than 3 bytes for the instruction encoding and executes in 3 rather than 4 cycles.

a6 00 ldx $00
ae 00 00 ldx $0000

This page is typically used by programs to store frequently accessed bookkeeping variables. In fact, the monitor program uses a few bytes stored at addresses $00ef-$00ff for various functions. The next page of RAM with addresses $0100-$01ff is used as stack by the 6502 microprocessor and should be left alone. From address $0200 all the way up to $13ff can be used freely though, which is why most programs start with the following command.

.org $0200

Addresses $1400-$173f are reserved for an optional second RIOT chip, but are otherwise unused in the default kit. You can verify this by trying to store anything in this range. Type AD, 1400, DA, followed by any value. No matter how hard you try, the data field in the LED display remains 00. Addresses $1740-$17ff are used by the 6532 RIOT chip. The functions of this peripheral chip are made available as regular memory addresses, a technique referred to as memory mapping. The 6532 provides 128 bytes of free RAM, two parallel I/O data ports, and programmable timers with interrupt capability. Details of this chip are given in later tutorials. For now, type AD 1744 while running the monitor program to get a surprise: the data field on the LED does not show one value, but cycles through many, as shown below.

Memory Mapped Address in the Micro-KIM.

Lastly, addresses $1800-$1fff are taken by the 2K EPROM that contains the monitor program, discussed earlier. Although you can use the monitor program to inspect its own values in this memory region, you can obviously not change the values by typing DA and a value. For example, after typing AD and 1FFF, the data field shows the value 1C corresponding to the second byte of IRQT, as can be seen in the listing of the monitor program in the appendix of the Setup and User’s Manual of Briel Computers. However, typing DA followed by any value has no effect, since this part addresses immutable ROM.

That's it again for now! Please like, share, or comment if you like this series. Also, note that the series is now available as single PDF on my Micro-KIM webpage.

Sunday, April 16, 2017

Micro-KIM Tutorial: Available as Single PDF

If you were following (and hopefully enjoying) the Micro-KIM tutorial, you may have noticed a rather long silence after the last posting. Unfortunately, my day job and a move plus remodeling claimed most of my spare time. However, I plan to continue the tutorial really soon again!

In the meanwhile, I have made all previous tutorials available as a single PDF on my Micro-KIM website, where you can also find the source code of all examples. Future tutorials will be added to this PDF to keep the collection available as a single file.

Thursday, October 13, 2016

New Chess Graphics for Chess for Android

Bryan Whitby, who contacted me earlier to tell about very cool USB chess board projects, contacted me recently with a very generous offer to use his awesome chess graphics in Chess for Android. I am very thankful, since these graphics look really good, and combine well with the various board types already supported. So, expect an updated on Android Play and my website really soon! And, thank you Bryan!







Sunday, May 22, 2016

Micro-KIM Tutorial: Brightness of LED Display

A demo is a program that shows off the abilities of a computer or programmer, sometimes even beyond the limits of an original architectural design. For example, a well-known demo theme on the Commodore 64 consists of rendering sprites in the border, i.e. outside the area originally destined for rendering sprites. This tutorial presents demos that use the LED display beyond its (probable) original purpose: adjusting the brightness of characters or even segments.

As shown in the previous tutorial, a refreshing loop is necessary to show all 6 characters on the LED display. Here, the refreshing rate directly defines the brightness of these characters. Simply looping around yields maximum brightness, while lowering the refresh rate dims the screen. This idea can also be used to adjust the brightness of parts of the LED screen (characters or even individual segments within the characters).

To illustrate this effect, let's modify the program of the previous tutorial (the source code of this and the modified program can be found on my Micro-KIM webpage). To focus on the brightness difference, only 'A's are shown. Also, rather than directly looping around, add a few new instructions right before the jump back.

             ....
             lda #0
             sta sad
             lda #11
             sta sbd
             lda #$f7  ; change to $40 for segment
             sta sad
             ldx #200
bright_delay dex
             bne bright_delay
             
             jmp display_loop

This new code glows up the second character for a while before looping around refreshing all other characters. The result of this change is that the second A on the LED display looks a lot brighter, as illustrated below (the effect looks a bit better on the actual kit than in this picture).

Single bright character (second A)

The same idea can be used to change the brightness of individual segments within characters. Changing the value $f7 into $40 as indicated in the comment above makes the center segment of the second A brighter than the rest of the display, as shown below (again, the effect looks a bit better on the actual kit).


Single bright segment (center segment in second A)

Finally, the idea gives rise to a wide variety of demos that change the brightness of the LED display somehow, such as fading the display in and out, sliding a glow effect over characters or segments, or giving emphasis to parts of the display. Give it a try and post your demo here as a comment. For starters, here is one of my sliding glow demos.

Sliding Glow Effect
That's it for this tutorial. As before, please like, share, or comment if you like this series!

Saturday, May 21, 2016

Micro-KIM Tutorial: The LED Display

The following schematic illustrates what is fun about retro computing: the complete schematic of a microcomputer fits on a single page (a higher resolution PDF can be downloaded from the Briel Computers website).

Micro-KIM Schematic. Courtesy Vince Briel - Briel Computers

The schematic shows that the 6 character LED display is controlled through some selection logic by the data ports of the 6532 RIOT. Because the 16 pins of the two 8-bit data ports A and B would not have sufficed to control all characters in the LED display simultaneously, instead a few bits of B select one character (value 9 selects the first, value 11 the second, etc.) while the lower 7 bits in A are used to control the 7 segments of that particular character (bit 0 controls the top segment, bit 1 upper right segment, etc.).

Note that with this scheme, it is possible to set one character and "go on with the program", as I showed in an earlier tutorial by displaying a very bright 8 in the first character, followed by simply looping the program (it could do something else instead). However, it is not possible to set all characters somehow, and "go on". Instead, the program has to loop over all characters and constantly refresh their contents. Due to the refreshing loop, displaying the full display appears a bit less bright than displaying a single character without such a loop.

Now let's write down some code to control the full LED display (as before, you can find the source code on my Micro-KIM webpage). First, some definitions provide symbolic names for the addresses of the data ports of the 6532 RIOT. The data registers contain the actual values, whereas the bits of the data direction registers define whether each pin is used for input (0) or output (1).

sad  = $1740   ; A data register
padd = $1741   ; A data direction register
sbd  = $1742   ; B data register
pbdd = $1743   ; B data direction register

Next some initialization code sets the 6532 RIOT data direction registers for output on the needed pins.

.org $0200
             lda #$7f
             sta padd
             lda #$3f
             sta pbdd

Then, the refreshing loop looks as follows. Here, register x iterates from 0 to 5 to load the proper value for the 7 segments of each character from a data array (with values that define the string "aart b"). Register y iterates from 9 to 19 with increment 2 to select each subsequent character on the LED display through data register B. Note that before changing data register B, the program clears data register A to ensure the old contents do not accidentally "flicker" very briefly in the next character. Furthermore, the program has a short delay when each next character is shown to ensure that character "glows up" a bit before moving on.

display_loop ldx #0
             ldy #9
char_loop    lda #0
             sta sad         ; no flicker
             sty sbd
             lda data, x
             sta sad
             txa
             ldx #4
char_delay   dex
             bne char_delay  ; glow up character
             tax
             inx
             iny
             iny
             cpx #6
             bne char_loop

             jmp display_loop ; keep refreshing

data .byte   $f7 $f7 $d0 $f8 $00 $fc

Assembling, uploading, and running this program as shown in earlier tutorials shows the following output on the LED display. Of course, feel free to change the values in the data array to your own custom-made characters.

Taking full control of the LED display

That's it for this tutorial. Next tutorials will talk more on controlling the brightness of the LED display, scrolling text, moving graphics, and using interrupts to implement the refreshing loop.