From 9abcca773bf15f6907d16df10673ed9b9cb81b68 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Fri, 21 May 2021 14:34:22 +0100 Subject: [PATCH] Made simple load/save examples composable --- projects/examples/devices/file.load.usm | 11 +++++++---- projects/examples/devices/file.save.usm | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/projects/examples/devices/file.load.usm b/projects/examples/devices/file.load.usm index a9790f7..5d30de7 100644 --- a/projects/examples/devices/file.load.usm +++ b/projects/examples/devices/file.load.usm @@ -12,8 +12,11 @@ ( program ) -|0100 @reset ( -> ) - +|0100 ( -> ) + ;try-load JSR2 + BRK + +@try-load ( -- ) ( load contents from file ) #1000 .File/length DEO2 ;filename .File/name DEO2 @@ -24,7 +27,7 @@ #f0f7 .System/r DEO2 #f0f7 .System/g DEO2 #00f7 .System/b DEO2 - BRK + JMP2r &success ( read successful: dark blue background, show contents ) @@ -32,7 +35,7 @@ #00f7 .System/g DEO2 #40f7 .System/b DEO2 ;contents DUP2 .File/success DEI2 ADD2 SWP2 ;draw JSR2 - BRK + JMP2r @draw ( end-ptr* ptr* -- ) EQU2k ,&end JCN diff --git a/projects/examples/devices/file.save.usm b/projects/examples/devices/file.save.usm index 8c85a1a..47116fc 100644 --- a/projects/examples/devices/file.save.usm +++ b/projects/examples/devices/file.save.usm @@ -3,6 +3,7 @@ ( devices ) |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] +|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] |a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ] ( variables ) @@ -11,8 +12,11 @@ ( init ) -|0100 @reset ( -> ) +|0100 ( -> ) + ;try-save JSR2 + BRK +@try-save ( -- ) ( save contents to file ) ;contents/end ;contents SUB2 .File/length DEO2 ;filename .File/name DEO2 @@ -23,16 +27,16 @@ #f0f7 .System/r DEO2 #f0f7 .System/g DEO2 #00f7 .System/b DEO2 - BRK + JMP2r &success ( write successful: dark blue background ) #00f7 .System/r DEO2 #00f7 .System/g DEO2 #40f7 .System/b DEO2 - BRK + JMP2r @filename "hello.txt 00 -@contents "Hello 20 "world, 20 "how 20 "are 20 "you? 0a +@contents "Hello 20 "world, 0a "how 20 "are 20 "you? 0a &end