Skip to content

Latest commit

 

History

History

examples

TMS9918A Example Programs

Here I provide assembly and C libraries for use with my TMS9918A video card. They have been tested using my TMS9918A card with Steve Cousin's SC126 Z180 motherboard, with Spencer Owen's RC2014 Zed kit, and with my own z80ctrl board. The demos will automatically detect the TMS9918A on common ports (ColecoVision on 0xBE, MSX on 0x98, Sord M5 on 0x10, or Tatung Einstein on 0x8). The demos also auto-detect a Z180 processor and some demos use the enhanced features the Z180 provides.

I have tried to come up with fun ways to demonstrate the various aspects of programming the TMS9918A video chip in the various examples.

Libraries

Assembly

  • tms.asm: Reusable TMS9918A library.
  • z180.asm: Reusable Z180 library.
  • utility.asm: Resuable BDOS and utility library.
  • tmsfont.asm: 6x8 bitmap font for use in text mode.
  • PT3.asm: PTx music player. Used to play the Nyan Cat theme on YM2149.

C

  • tmsc.asm: zz8dk wrapper for assembly library.
  • tms.h: C header for z88dk library wrapper.
  • font.h: same 6x8 bitmap font in a C header.

Examples

Assembly

  • ascii.asm: ASCII character set. Demonstrates text mode.
  • mandel.asm: Mandelbrot renderer. Demonstrates pseudo-bitmap graphics (Graphics II Mode).
  • nyan.asm: Nyan Cat. Demonstrates multi-color mode. Change the incbin directives to binary for z88dk's assembler.
  • plasma.asm: Plasma effect. Demonstrates tiled graphics (Graphics I Mode).
  • sprite.asm: Bouncing globe. Demonstrates sprites.

I have tried to stick to a common subset of assembler features that will work with any of the following cross-assemblers:

  • Sjasm: Windows binaries available for download. Compiles on Linux using sources on Github.
  • SjasmPlus: Windows binaries available for download. Compiles on Linux using sources on Github.
  • z80asm: Binaries available in the Debian repository. Mac binaries on Homebrew. Compiles on Windows.
  • z88dk's z80asm (not to be confused with z80asm above). Windows and Mac binaries available for download. Compiles on Linux.
  • pasmo: Windows and Mac binaries available for download. Binaries available in the Debain repository.

My preferred assembler is sjasm. Although I try to maintain compatibility with all of the above, I may not always test every change against the others. If you have trouble assembling with any of the above, please try sjasm, and file a bug to let me know about the problem.

C

  • hello.c: Text mode demonstration for C wrapper.
  • fern.c: Barnsley Fern. Demonstrates bitmap pixel-addressable mode via C wrapper.
  • hopalong.c: Hopalong Attractor. Demonstrates pixel-addressable mode via C wrapper.

The C examples and libraries are compatible with z88dk. Binaries available for download, and it compiles on Linux. With some effort, the code may be adapted to other Z80 C compilers, but I have not tried.

MSX-BASIC

  • fern.bas: Barnsley Fern in MSX-BASIC.
  • hopalong.bas: Hopalong Attractor in MSX-BASIC.

The BASIC examples require the graphic primitives of MSX-BASIC. See my instructions for running MSX-BASIC on z80ctrl and TMS9918A video card.

Credits

  • PT3.asm comes from PtxTools by Sergey Bulba, with modifications from RomWBW by Wayne Warthen.
  • tmsfont.asm and font.h come from Raster Fonts by Oleg Kosenov.
  • mandel.asm uses fixed point Mandelbrot routine originally from Rosetta Code. It has been enhanced with table-based multiplication from CPC Wiki and Z180 hardware multiplication routines by Phillip Stevens.
  • nyan.asm has Nyan Cat animations from Passan Kiskat by Dromedaar Vision and the Nyan Cat song by Karbofos.
  • plasma.asm is converted from a 6809 program by Matt Sarnoff.
  • sprite.asm uses globe bitmaps from the TI VDP Programmer's Guide.
  • fern.c and fern.bas are implementations of the Barnsley Fern IFS fractal first described by Michael Barnsley.
  • hopalong.c and hopalong.bas are implementations of the Hopalong Attractor discovered by Barry Martin of Aston University and named by A.K. Dewdney in his Computer Recreations column in the September 1986 issue of Scientific American.
  • The remaining code was written by me, J.B. Langston. Specifically, the tms.asm, tmsc.asm, z180.asm, utility.asm and tms.h library files are my own work.