Skip to content

Commit

Permalink
rendering test
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Aug 16, 2024
1 parent 2100df1 commit b7e8f24
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 3 deletions.
47 changes: 47 additions & 0 deletions internal/rendertest/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"image"
"image/png"
"log"
"os"
"time"

"github.com/koron-go/vdp/tms9918"
)

func main() {
vdp := tms9918.New(make([]uint8, 16384))
tms9918.MSXScreen1(vdp)
tms9918.SetupReferencePattern(vdp)
// setup color
vdp.Register7 = 0x07
for i := range 32 {
vdp.VRAM[0x2000+i] = 0xF4
}
// setup name table
for i := 0x20; i <= 0x7F; i++ {
vdp.VRAM[0x1800+i] = uint8(i)
}

// render
img, err := vdp.NewPaletted(image.Rect(0, 0, 256+32, 192+32))
if err != nil {
log.Fatal(err)
}
start := time.Now()
vdp.Render(img)
dur := time.Since(start)
log.Printf("rendered in %d", dur)

// output as PNG
f, err := os.Create("test.png")
if err != nil {
log.Fatal(err)
}
err = png.Encode(f, img)
f.Close()
if err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion tms9918/msx.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tsm9918
package tms9918

func MSXScreen0(vdp *VDP) {
vdp.Register2.ResetSet(0x0F, 0x00) // 0x0000: name table
Expand Down
2 changes: 1 addition & 1 deletion tms9918/msx_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tsm9918
package tms9918

import (
"testing"
Expand Down
107 changes: 107 additions & 0 deletions tms9918/pattern.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package tms9918

var ReferencePattern = []uint8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // (SPACE)
0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x00, // !
0x50, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, // "
0x50, 0x50, 0xF8, 0x50, 0xF8, 0x50, 0x50, 0x00, // #
0x20, 0x78, 0xA0, 0x70, 0x28, 0xF0, 0x20, 0x00, // $
0xC0, 0xC8, 0x10, 0x20, 0x40, 0x98, 0x18, 0x00, // %
0x40, 0xA0, 0xA0, 0x40, 0xA8, 0x90, 0x68, 0x00, // &
0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // '
0x20, 0x40, 0x80, 0x80, 0x80, 0x40, 0x20, 0x00, // (
0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, // )
0x20, 0xA8, 0x70, 0x20, 0x70, 0xA8, 0x20, 0x00, // *
0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, // +
0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, // ,
0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, // -
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, // .
0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, // /
0x70, 0x88, 0x98, 0xA8, 0xC8, 0x88, 0x70, 0x00, // 0
0x20, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, // 1
0x70, 0x88, 0x08, 0x30, 0x40, 0x80, 0xF8, 0x00, // 2
0xF8, 0x08, 0x10, 0x30, 0x08, 0x88, 0x70, 0x00, // 3
0x10, 0x30, 0x50, 0x90, 0xF8, 0x10, 0x10, 0x00, // 4
0xF8, 0x80, 0xF0, 0x08, 0x08, 0x88, 0x70, 0x00, // 5
0x38, 0x40, 0x80, 0xF0, 0x88, 0x88, 0x70, 0x00, // 6
0xF8, 0x08, 0x10, 0x20, 0x40, 0x40, 0x40, 0x00, // 7
0x70, 0x88, 0x88, 0x70, 0x88, 0x88, 0x70, 0x00, // 8
0x70, 0x88, 0x88, 0x78, 0x08, 0x10, 0xE0, 0x00, // 9
0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, // :
0x00, 0x00, 0x20, 0x00, 0x20, 0x20, 0x40, 0x00, // ;
0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x00, // <
0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, // =
0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00, // >
0x70, 0x88, 0x10, 0x20, 0x20, 0x00, 0x20, 0x00, // ?

0x70, 0x88, 0xA8, 0xB8, 0xB0, 0x80, 0x78, 0x00, // @
0x20, 0x50, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x00, // A
0xF0, 0x88, 0x88, 0xF0, 0x88, 0x88, 0xF0, 0x00, // B
0x70, 0x88, 0x80, 0x80, 0x80, 0x88, 0x70, 0x00, // C
0xF0, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF0, 0x00, // D
0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF0, 0x00, // E
0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00, // F
0x78, 0x80, 0x80, 0x80, 0x98, 0x88, 0x78, 0x00, // G
0x88, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x00, // H
0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, // I
0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, // J
0x88, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x88, 0x00, // K
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, // L
0x88, 0xD8, 0xA8, 0xA8, 0x88, 0x88, 0x88, 0x00, // M
0x88, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x88, 0x00, // N
0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, // O
0xF0, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x00, // P
0x70, 0x88, 0x88, 0x88, 0xA8, 0x90, 0x68, 0x00, // Q
0xF0, 0x88, 0x88, 0xF0, 0xA0, 0x90, 0x88, 0x00, // R
0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70, 0x00, // S
0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, // T
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, // U
0x88, 0x88, 0x88, 0x88, 0x88, 0x50, 0x20, 0x00, // V
0x88, 0x88, 0x88, 0xA8, 0xA8, 0xD8, 0x88, 0x00, // W
0x88, 0x88, 0x50, 0x20, 0x50, 0x88, 0x88, 0x00, // X
0x88, 0x88, 0x50, 0x20, 0x20, 0x20, 0x20, 0x00, // Y
0xF8, 0x08, 0x10, 0x20, 0x40, 0x80, 0xF8, 0x00, // Z
0xF8, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xF8, 0x00, // [
0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, // \
0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, // ]
0x00, 0x00, 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, // ^
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, // _

0x40, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // `
0x00, 0x00, 0x70, 0x88, 0xF8, 0x88, 0x88, 0x00, // a
0x00, 0x00, 0xF0, 0x48, 0x70, 0x48, 0xF0, 0x00, // b
0x00, 0x00, 0x78, 0x80, 0x80, 0x80, 0x78, 0x00, // c
0x00, 0x00, 0xF0, 0x48, 0x48, 0x48, 0xF0, 0x00, // d
0x00, 0x00, 0xF0, 0x80, 0xE0, 0x80, 0xF0, 0x00, // e
0x00, 0x00, 0xF0, 0x80, 0xE0, 0x80, 0x80, 0x00, // f
0x00, 0x00, 0x78, 0x80, 0xB8, 0x88, 0x70, 0x00, // g
0x00, 0x00, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x00, // h
0x00, 0x00, 0xF8, 0x20, 0x20, 0x20, 0xF8, 0x00, // i
0x00, 0x00, 0x70, 0x20, 0x20, 0xA0, 0xE0, 0x00, // j
0x00, 0x00, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x00, // k
0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, // l
0x00, 0x00, 0x88, 0xD8, 0xA8, 0x88, 0x88, 0x00, // m
0x00, 0x00, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x00, // n
0x00, 0x00, 0xF8, 0x88, 0x88, 0x88, 0xF8, 0x00, // o
0x00, 0x00, 0xF0, 0x88, 0xF0, 0x80, 0x80, 0x00, // p
0x00, 0x00, 0xF8, 0x88, 0xA8, 0x90, 0xE0, 0x00, // q
0x00, 0x00, 0xF8, 0x88, 0xF8, 0xA0, 0x90, 0x00, // r
0x00, 0x00, 0x78, 0x80, 0x70, 0x08, 0xF0, 0x00, // s
0x00, 0x00, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x00, // t
0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, // u
0x00, 0x00, 0x88, 0x88, 0x90, 0xA0, 0x40, 0x00, // v
0x00, 0x00, 0x88, 0x88, 0xA8, 0xD8, 0x88, 0x00, // w
0x00, 0x00, 0x88, 0x50, 0x20, 0x50, 0x88, 0x00, // x
0x00, 0x00, 0x88, 0x50, 0x20, 0x20, 0x20, 0x00, // y
0x00, 0x00, 0xF8, 0x10, 0x20, 0x40, 0xF8, 0x00, // z
0x38, 0x40, 0x20, 0xC0, 0x20, 0x40, 0x38, 0x00, // {
0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00, // |
0xE0, 0x10, 0x20, 0x18, 0x20, 0x10, 0xE0, 0x00, // }
0x40, 0xA8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ~
0xA8, 0x50, 0xA8, 0x50, 0xA8, 0x50, 0xA8, 0x00, // (0x7F)
}

func SetupReferencePattern(vdp *VDP) {
start := vdp.patternGeneratorBaseAddress() + 8*0x20
copy(vdp.VRAM[start:start+len(ReferencePattern)], ReferencePattern)
}
2 changes: 1 addition & 1 deletion tms9918/tms9918.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tsm9918
package tms9918

import (
"errors"
Expand Down

0 comments on commit b7e8f24

Please sign in to comment.