mirror of
https://github.com/irmen/prog8.git
synced 2024-11-18 19:12:44 +00:00
added bitmap characters
This commit is contained in:
parent
a7abc32368
commit
7b650ffa18
@ -5,6 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
@ -36,7 +36,8 @@
|
||||
if irq.time_changed {
|
||||
irq.time_changed = 0
|
||||
_vm_gfx_clearscr(0)
|
||||
_vm_gfx_text(14, 5, 5, "Spin to Win !!!")
|
||||
_vm_gfx_text(8, 6, 1, "Spin")
|
||||
_vm_gfx_text(29, 11, 1, "to Win !")
|
||||
|
||||
for i in 0 to width//10 {
|
||||
_vm_gfx_line(i*2+width//2-width//10, 130, i*10.w, 199, 6)
|
||||
|
@ -21,7 +21,7 @@
|
||||
byte ploty
|
||||
|
||||
_vm_gfx_clearscr(11)
|
||||
_vm_gfx_text(2, 1, 7, "Calculating Mandelbrot Fractal...")
|
||||
_vm_gfx_text(2, 1, 1, "Calculating Mandelbrot Fractal...")
|
||||
|
||||
for pixely in yoffset to yoffset+height-1 {
|
||||
yy = flt((pixely-yoffset))/height/3.6+0.4
|
||||
@ -46,7 +46,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
_vm_gfx_text(11, 21, 7, "Finished!")
|
||||
_vm_gfx_text(11, 21, 1, "Finished!")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
sub start() {
|
||||
|
||||
_vm_gfx_clearscr(0)
|
||||
_vm_gfx_text(2, 2, 7, "Swirl !!!")
|
||||
|
||||
float x
|
||||
float y
|
||||
|
BIN
compiler/res/charset/c64/charset-normal.png
Normal file
BIN
compiler/res/charset/c64/charset-normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
BIN
compiler/res/charset/c64/charset-shifted.png
Normal file
BIN
compiler/res/charset/c64/charset-shifted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
37
compiler/src/prog8/compiler/target/c64/Charset.kt
Normal file
37
compiler/src/prog8/compiler/target/c64/Charset.kt
Normal file
@ -0,0 +1,37 @@
|
||||
package prog8.compiler.target.c64
|
||||
|
||||
import java.awt.Color
|
||||
import java.awt.image.BufferedImage
|
||||
import javax.imageio.ImageIO
|
||||
|
||||
object Charset {
|
||||
private val normalImg = ImageIO.read(javaClass.getResource("/charset/c64/charset-normal.png"))
|
||||
private val shiftedImg = ImageIO.read(javaClass.getResource("/charset/c64/charset-shifted.png"))
|
||||
|
||||
private fun scanChars(img: BufferedImage): Array<BufferedImage> {
|
||||
|
||||
val transparent = BufferedImage(img.width, img.height, BufferedImage.TYPE_INT_ARGB)
|
||||
transparent.createGraphics().drawImage(img, 0, 0, null)
|
||||
|
||||
val black = Color(0,0,0).rgb
|
||||
val nopixel = Color(0,0,0,0).rgb
|
||||
for(y in 0 until transparent.height) {
|
||||
for(x in 0 until transparent.width) {
|
||||
val col = transparent.getRGB(x, y)
|
||||
if(col==black)
|
||||
transparent.setRGB(x, y, nopixel)
|
||||
}
|
||||
}
|
||||
|
||||
val numColumns = transparent.width / 8
|
||||
val charImages = (0..255).map {
|
||||
val charX = it % numColumns
|
||||
val charY = it/ numColumns
|
||||
transparent.getSubimage(charX*8, charY*8, 8, 8)
|
||||
}
|
||||
return charImages.toTypedArray()
|
||||
}
|
||||
|
||||
val normalChars = scanChars(normalImg)
|
||||
val shiftedChars = scanChars(shiftedImg)
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package prog8.stackvm
|
||||
|
||||
import prog8.compiler.target.c64.Charset
|
||||
import prog8.compiler.target.c64.Petscii
|
||||
import java.awt.*
|
||||
import java.awt.image.BufferedImage
|
||||
import javax.swing.JButton
|
||||
@ -13,7 +15,6 @@ class BitmapScreenPanel : JPanel() {
|
||||
private val image = BufferedImage(SCREENWIDTH, SCREENHEIGHT, BufferedImage.TYPE_INT_ARGB)
|
||||
private val g2d = image.graphics as Graphics2D
|
||||
|
||||
|
||||
init {
|
||||
val size = Dimension(image.width * SCALING, image.height * SCALING)
|
||||
minimumSize = size
|
||||
@ -42,9 +43,22 @@ class BitmapScreenPanel : JPanel() {
|
||||
g2d.drawLine(x1, y1, x2, y2)
|
||||
}
|
||||
fun writeText(x: Int, y: Int, text: String, color: Int) {
|
||||
g2d.font = Font(Font.MONOSPACED, Font.PLAIN, 10)
|
||||
g2d.color = palette[color and 15]
|
||||
g2d.drawString(text, x, y + g2d.font.size - 1)
|
||||
if(color!=1) {
|
||||
TODO("text can only be white for now")
|
||||
}
|
||||
var xx=x
|
||||
var yy=y
|
||||
for(sc in Petscii.encodeScreencode(text, true)) {
|
||||
setChar(xx, yy, sc)
|
||||
xx++
|
||||
if(xx>=(SCREENWIDTH/8)) {
|
||||
yy++
|
||||
xx=0
|
||||
}
|
||||
}
|
||||
}
|
||||
fun setChar(x: Int, y: Int, screenCode: Short) {
|
||||
g2d.drawImage(Charset.shiftedChars[screenCode.toInt()], 8*x, 8*y , null)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1375,7 +1375,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
val color = evalstack.pop()
|
||||
val (cy, cx) = evalstack.pop2()
|
||||
val text = heap.get(textPtr.heapId)
|
||||
canvas?.writeText(8*cx.integerValue(), 8*cy.integerValue(), text.str!!, color.integerValue())
|
||||
canvas?.writeText(cx.integerValue(), cy.integerValue(), text.str!!, color.integerValue())
|
||||
}
|
||||
Syscall.FUNC_RND -> evalstack.push(Value(DataType.BYTE, rnd.nextInt() and 255))
|
||||
Syscall.FUNC_RNDW -> evalstack.push(Value(DataType.WORD, rnd.nextInt() and 65535))
|
||||
|
Loading…
Reference in New Issue
Block a user